Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/private/Files/Cache/CacheEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function __clone() {

#[\Override]
public function getUnencryptedSize(): int {
if ($this->data['encrypted'] && isset($this->data['unencrypted_size']) && $this->data['unencrypted_size'] > 0) {
if ($this->data['encrypted'] && isset($this->data['unencrypted_size'])) {
return $this->data['unencrypted_size'];
} else {
return $this->data['size'] ?? 0;
Expand Down
15 changes: 12 additions & 3 deletions lib/private/Files/Cache/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,12 @@ public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData =
}
}

// we only updated unencrypted_size if it's already set
if (isset($cacheData['unencrypted_size']) && $cacheData['unencrypted_size'] === 0) {
// Only skip updating unencrypted_size if both cached and new values are 0
// This allows updating from incorrect cached 0 to correct non-zero value
// while avoiding unnecessary updates when both are legitimately 0
if (isset($cacheData['unencrypted_size'])
&& $cacheData['unencrypted_size'] === 0
&& (!isset($data['unencrypted_size']) || $data['unencrypted_size'] === 0)) {
unset($data['unencrypted_size']);
}

Expand All @@ -202,7 +206,12 @@ public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData =
$data['etag_changed'] = true;
}
} else {
unset($data['unencrypted_size']);
// For new files, preserve unencrypted_size only when the file is encrypted
// and the key is present; otherwise clear it so it won't be written stale.
if (!isset($data['encrypted']) || !$data['encrypted']
|| !isset($data['unencrypted_size'])) {
unset($data['unencrypted_size']);
}
$newData = $data;
$fileId = -1;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function getSize($includeMounts = true) {
if ($includeMounts) {
$this->updateEntryFromSubMounts();

if ($this->isEncrypted() && isset($this->data['unencrypted_size']) && $this->data['unencrypted_size'] > 0) {
if ($this->isEncrypted() && isset($this->data['unencrypted_size'])) {
return $this->data['unencrypted_size'];
} else {
return isset($this->data['size']) ? 0 + $this->data['size'] : 0;
Expand Down
1 change: 1 addition & 0 deletions lib/private/Files/Storage/Wrapper/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ protected function verifyUnencryptedSize(string $path, int $unencryptedSize): in
if ($unencryptedSize < 0
|| ($size > 0 && $unencryptedSize === $size)
|| $unencryptedSize > $size
|| ($unencryptedSize === 0 && $size > $this->util->getHeaderSize())
) {
// check if we already calculate the unencrypted size for the
// given path to avoid recursions
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Stream/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Encryption extends Wrapper {
protected string $cache;
protected ?int $size = null;
protected int $position;
protected ?int $unencryptedSize = null;
protected int|float|null $unencryptedSize = null;
protected int $headerSize;
protected int $unencryptedBlockSize;
protected array $header;
Expand Down
Loading