From 4151fd3ed945dd07dac12c7612a439e7f2a0b8d9 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 14 Oct 2013 16:34:14 +0200 Subject: try to fix unencrypted file size if it doesn't look plausible --- apps/files_encryption/lib/proxy.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'apps/files_encryption') diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index 8621c1ba51d..f8d10bdcd8b 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -316,6 +316,16 @@ class Proxy extends \OC_FileProxy { $view = new \OC_FilesystemView('/'); + $userId = \OCP\User::getUser(); + $util = new Util($view, $userId); + + // if encryption is no longer enabled or if the files aren't migrated yet + // we return the default file size + if(!\OCP\App::isEnabled('files_encryption') || + $util->getMigrationStatus() !== Util::MIGRATION_COMPLETED) { + return $size; + } + // if path is a folder do nothing if ($view->is_dir($path)) { return $size; @@ -337,6 +347,15 @@ class Proxy extends \OC_FileProxy { // if file is encrypted return real file size if (is_array($fileInfo) && $fileInfo['encrypted'] === true) { + // try to fix unencrypted file size if it doesn't look plausible + if ((int)$fileInfo['size'] > 0 && (int)$fileInfo['encrypted_size'] === 0) { + $fixSize = $util->getFileSize($path); + $fileInfo['unencrypted_size'] = $fixSize; + // put file info if not .part file + if (!Keymanager::isPartialFilePath($relativePath)) { + $view->putFileInfo($path, $fileInfo); + } + } $size = $fileInfo['unencrypted_size']; } else { // self healing if file was removed from file cache @@ -344,8 +363,6 @@ class Proxy extends \OC_FileProxy { $fileInfo = array(); } - $userId = \OCP\User::getUser(); - $util = new Util($view, $userId); $fixSize = $util->getFileSize($path); if ($fixSize > 0) { $size = $fixSize; -- cgit v1.2.3 From 58196304b8cafa2762f9662c188bc4eed2c11651 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 14 Oct 2013 16:43:18 +0200 Subject: fix array key --- apps/files_encryption/lib/proxy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/files_encryption') diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index f8d10bdcd8b..042becb32e3 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -348,7 +348,7 @@ class Proxy extends \OC_FileProxy { // if file is encrypted return real file size if (is_array($fileInfo) && $fileInfo['encrypted'] === true) { // try to fix unencrypted file size if it doesn't look plausible - if ((int)$fileInfo['size'] > 0 && (int)$fileInfo['encrypted_size'] === 0) { + if ((int)$fileInfo['size'] > 0 && (int)$fileInfo['unencrypted_size'] === 0) { $fixSize = $util->getFileSize($path); $fileInfo['unencrypted_size'] = $fixSize; // put file info if not .part file -- cgit v1.2.3 From 0811d2e30443de46f8e1202ec09c3c93fed87f2c Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 15 Oct 2013 17:52:06 +0200 Subject: added another test, if unencrypted size and encrypted size are equal we can also assume that something is wrong --- apps/files_encryption/lib/proxy.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'apps/files_encryption') diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index 042becb32e3..1a950122119 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -348,7 +348,9 @@ class Proxy extends \OC_FileProxy { // if file is encrypted return real file size if (is_array($fileInfo) && $fileInfo['encrypted'] === true) { // try to fix unencrypted file size if it doesn't look plausible - if ((int)$fileInfo['size'] > 0 && (int)$fileInfo['unencrypted_size'] === 0) { + if ((int)$fileInfo['size'] > 0 && + ((int)$fileInfo['unencrypted_size'] === 0 || + (int)$fileInfo['size'] === (int)$fileInfo['unencrypted_size'])) { $fixSize = $util->getFileSize($path); $fileInfo['unencrypted_size'] = $fixSize; // put file info if not .part file -- cgit v1.2.3 From 6bfd8bdf63329460a472462a60d40d3b345f42e0 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 16 Oct 2013 11:24:56 +0200 Subject: revert last changes --- apps/files_encryption/lib/proxy.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'apps/files_encryption') diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index 1a950122119..fa1a4703573 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -348,9 +348,7 @@ class Proxy extends \OC_FileProxy { // if file is encrypted return real file size if (is_array($fileInfo) && $fileInfo['encrypted'] === true) { // try to fix unencrypted file size if it doesn't look plausible - if ((int)$fileInfo['size'] > 0 && - ((int)$fileInfo['unencrypted_size'] === 0 || - (int)$fileInfo['size'] === (int)$fileInfo['unencrypted_size'])) { + if ((int)$fileInfo['size'] > 0 && (int)$fileInfo['unencrypted_size'] === 0 ) { $fixSize = $util->getFileSize($path); $fileInfo['unencrypted_size'] = $fixSize; // put file info if not .part file -- cgit v1.2.3