X Tutup
Skip to content

Commit b831feb

Browse files
author
Pasquale Tripodi
authored
Prevent 507 Insufficient Storage on 32-bit systems (#40709)
* prevent 507 Insufficient Storage on 32bit systems * add changelog * improve if-else logic * retrigger CI
1 parent d51cb0a commit b831feb

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

apps/dav/lib/Connector/Sabre/QuotaPlugin.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,25 @@ public function checkQuota($path, $length = null, $extraSpace = 0) {
204204
$path = \rtrim($parentPath, '/') . '/' . $info['name'];
205205
}
206206
$freeSpace = $this->getFreeSpace($path);
207-
// freeSpace might be false, or an int. Anyway, make sure that availableSpace will be an int.
208-
$availableSpace = (int) $freeSpace + $extraSpace;
209-
if ($freeSpace !== FileInfo::SPACE_UNKNOWN && $freeSpace !== FileInfo::SPACE_UNLIMITED && (($length > $availableSpace) || ($availableSpace === 0))) {
210-
if (isset($chunkHandler)) {
211-
$chunkHandler->cleanup();
207+
// workaround to guarantee compatibility on 32-bit systems as otherwise this would cause an int overflow on such systems
208+
// when $freeSpace is above the max supported value. $freeSpace should be a float so we are using the <= 0.0 comparison
209+
if (PHP_INT_SIZE === 4) {
210+
$availableSpace = $freeSpace + $extraSpace;
211+
if ($freeSpace !== FileInfo::SPACE_UNKNOWN && $freeSpace !== FileInfo::SPACE_UNLIMITED && (($length > $availableSpace) || ($availableSpace <= 0.0))) {
212+
if (isset($chunkHandler)) {
213+
$chunkHandler->cleanup();
214+
}
215+
throw new InsufficientStorage();
216+
}
217+
} else {
218+
// freeSpace might be false, or an int. Anyway, make sure that availableSpace will be an int.
219+
$availableSpace = (int) $freeSpace + $extraSpace;
220+
if ($freeSpace !== FileInfo::SPACE_UNKNOWN && $freeSpace !== FileInfo::SPACE_UNLIMITED && (($length > $availableSpace) || ($availableSpace === 0))) {
221+
if (isset($chunkHandler)) {
222+
$chunkHandler->cleanup();
223+
}
224+
throw new InsufficientStorage();
212225
}
213-
throw new InsufficientStorage();
214226
}
215227
}
216228
return true;

changelog/unreleased/40709

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Bugfix: Prevent 507 Insufficient Storage on 32-bit systems
2+
3+
With the introduction of https://github.com/owncloud/core/pull/40567 compatibility to 32-bit systems broke as we are now casting $freeSpace to int and this caused an integer overflow on such systems when the free space was above the max supported value. We added therefore an additional check for 32-bit systems in QuotaPlugin.php.

0 commit comments

Comments
 (0)
X Tutup