diff options
author | Robin Appelman <robin@icewind.nl> | 2025-05-09 16:37:06 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2025-05-09 22:33:45 +0200 |
commit | b0b8159d6a3777c1c7b9cfa1c5e74974b5c0273c (patch) | |
tree | e91fc980d304289a4a5ca0dd3ada4c8c9d3a9f54 /lib/private | |
parent | c7430d5cb806ac2cf84d2e6e7ae1da3f50375828 (diff) | |
download | nextcloud-server-b0b8159d6a3777c1c7b9cfa1c5e74974b5c0273c.tar.gz nextcloud-server-b0b8159d6a3777c1c7b9cfa1c5e74974b5c0273c.zip |
fix: throw a better error if we can't get the encrypted header sizeencryption-no-header-size-error
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Encryption.php | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/private/Files/Storage/Wrapper/Encryption.php b/lib/private/Files/Storage/Wrapper/Encryption.php index ba23f3c43ec..0de009f0894 100644 --- a/lib/private/Files/Storage/Wrapper/Encryption.php +++ b/lib/private/Files/Storage/Wrapper/Encryption.php @@ -18,6 +18,7 @@ use OC\Files\Storage\Common; use OC\Files\Storage\LocalTempFileTrait; use OC\Memcache\ArrayCache; use OCP\Cache\CappedMemoryCache; +use OCP\Encryption\Exceptions\InvalidHeaderException; use OCP\Encryption\IFile; use OCP\Encryption\IManager; use OCP\Encryption\Keys\IStorage; @@ -344,6 +345,16 @@ class Encryption extends Wrapper { if ($shouldEncrypt === true && $encryptionModule !== null) { $this->encryptedPaths->set($this->util->stripPartialFileExtension($path), true); $headerSize = $this->getHeaderSize($path); + if ($mode === 'r' && $headerSize === 0) { + $firstBlock = $this->readFirstBlock($path); + if (!$firstBlock) { + throw new InvalidHeaderException("Unable to get header block for $path"); + } elseif (!str_starts_with($firstBlock, Util::HEADER_START)) { + throw new InvalidHeaderException("Unable to get header size for $path, file doesn't start with encryption header"); + } else { + throw new InvalidHeaderException("Unable to get header size for $path, even though file does start with encryption header"); + } + } $source = $this->storage->fopen($path, $mode); if (!is_resource($source)) { return false; |