diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2021-04-06 13:45:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-06 13:45:10 +0200 |
commit | 4b4971ab5245dd1b9dd27fd2e293367c8fa037c0 (patch) | |
tree | 7c1787792a2f7457c991773df8ae6b82a29fd434 /lib/private/Files/Storage/Wrapper/Encryption.php | |
parent | 2056b76c5fb29fa9273c50e17e54c5cf43f8a5fc (diff) | |
parent | 40fde94b4d019f5c1914225d5be6854241abeb9c (diff) | |
download | nextcloud-server-4b4971ab5245dd1b9dd27fd2e293367c8fa037c0.tar.gz nextcloud-server-4b4971ab5245dd1b9dd27fd2e293367c8fa037c0.zip |
Merge pull request #24966 from nextcloud/jknockaert-patch-1
avoid fread on directories and unencrypted files
Diffstat (limited to 'lib/private/Files/Storage/Wrapper/Encryption.php')
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Encryption.php | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/lib/private/Files/Storage/Wrapper/Encryption.php b/lib/private/Files/Storage/Wrapper/Encryption.php index a7a915afad9..64c9b0a4a66 100644 --- a/lib/private/Files/Storage/Wrapper/Encryption.php +++ b/lib/private/Files/Storage/Wrapper/Encryption.php @@ -925,21 +925,20 @@ class Encryption extends Wrapper { $path = $realFile; } - $firstBlock = $this->readFirstBlock($path); - $result = $this->parseRawHeader($firstBlock); + $result = []; + + // first check if it is an encrypted file at all + // We would do query to filecache only if we know that entry in filecache exists + + $info = $this->getCache()->get($path); + if (isset($info['encrypted']) && $info['encrypted'] === true) { + $firstBlock = $this->readFirstBlock($path); + $result = $this->parseRawHeader($firstBlock); - // if the header doesn't contain a encryption module we check if it is a - // legacy file. If true, we add the default encryption module - if (!isset($result[Util::HEADER_ENCRYPTION_MODULE_KEY])) { - if (!empty($result)) { + // if the header doesn't contain a encryption module we check if it is a + // legacy file. If true, we add the default encryption module + if (!isset($result[Util::HEADER_ENCRYPTION_MODULE_KEY]) && (!empty($result) || $exists)) { $result[Util::HEADER_ENCRYPTION_MODULE_KEY] = 'OC_DEFAULT_MODULE'; - } elseif ($exists) { - // if the header was empty we have to check first if it is a encrypted file at all - // We would do query to filecache only if we know that entry in filecache exists - $info = $this->getCache()->get($path); - if (isset($info['encrypted']) && $info['encrypted'] === true) { - $result[Util::HEADER_ENCRYPTION_MODULE_KEY] = 'OC_DEFAULT_MODULE'; - } } } |