summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJasper Knockaert <jasper@knockaert.nl>2021-01-05 11:14:49 +0100
committerMichaIng (Rebase PR Action) <micha@dietpi.com>2021-09-03 13:40:40 +0000
commit82482adb483e1963be8fb5deedb24dca9d252708 (patch)
tree47666a5292d011a05c218f0c2a0e1981eb1d7647 /lib
parent9d9f8d04fbcbf1a956d5ffd5ef06821baec3d20d (diff)
downloadnextcloud-server-82482adb483e1963be8fb5deedb24dca9d252708.tar.gz
nextcloud-server-82482adb483e1963be8fb5deedb24dca9d252708.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')
-rw-r--r--lib/private/Files/Storage/Wrapper/Encryption.php29
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 a7a915afad9..7482212157e 100644
--- a/lib/private/Files/Storage/Wrapper/Encryption.php
+++ b/lib/private/Files/Storage/Wrapper/Encryption.php
@@ -925,19 +925,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';
}
}