diff options
author | Jasper Knockaert <jasper@knockaert.nl> | 2021-01-05 11:14:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-05 11:14:49 +0100 |
commit | 81e3ae4753774cf33e6f5bcaf1dc479e1dc5831c (patch) | |
tree | f68d52b640de6faf860777a346e070c570efe76d /lib/private/Files | |
parent | 39c67d9868d15fa42031b8bafebc6bc05eac867e (diff) | |
download | nextcloud-server-81e3ae4753774cf33e6f5bcaf1dc479e1dc5831c.tar.gz nextcloud-server-81e3ae4753774cf33e6f5bcaf1dc479e1dc5831c.zip |
avoid fread on directories and unencrypted files
Reworking the logic in order to first check the filecache and only then reading the fileheader.
This in order to solve #21578.
Diffstat (limited to 'lib/private/Files')
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Encryption.php | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/lib/private/Files/Storage/Wrapper/Encryption.php b/lib/private/Files/Storage/Wrapper/Encryption.php index ef44be5cefb..b37fcdb2bd0 100644 --- a/lib/private/Files/Storage/Wrapper/Encryption.php +++ b/lib/private/Files/Storage/Wrapper/Encryption.php @@ -929,19 +929,22 @@ class Encryption extends Wrapper { $path = $realFile; } - $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)) { - $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 = []; + + // 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)) { + $result[Util::HEADER_ENCRYPTION_MODULE_KEY] = 'OC_DEFAULT_MODULE'; + } elseif ($exists) { $result[Util::HEADER_ENCRYPTION_MODULE_KEY] = 'OC_DEFAULT_MODULE'; } } |