Merge pull request #24966 from nextcloud/jknockaert-patch-1
avoid fread on directories and unencrypted files
This commit is contained in:
commit
4b4971ab52
|
@ -925,21 +925,20 @@ class Encryption extends Wrapper {
|
|||
$path = $realFile;
|
||||
}
|
||||
|
||||
$firstBlock = $this->readFirstBlock($path);
|
||||
$result = $this->parseRawHeader($firstBlock);
|
||||
$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])) {
|
||||
if (!empty($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]) && (!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';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -585,6 +585,14 @@ class EncryptionTest extends Storage {
|
|||
]
|
||||
)->getMock();
|
||||
|
||||
$cache = $this->getMockBuilder('\OC\Files\Cache\Cache')
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$cache->expects($this->any())
|
||||
->method('get')
|
||||
->willReturnCallback(function ($path) {
|
||||
return ['encrypted' => true, 'path' => $path];
|
||||
});
|
||||
|
||||
$instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption')
|
||||
->setConstructorArgs(
|
||||
[
|
||||
|
@ -597,9 +605,11 @@ class EncryptionTest extends Storage {
|
|||
$this->encryptionManager, $util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager, $this->arrayCache
|
||||
]
|
||||
)
|
||||
->setMethods(['readFirstBlock', 'parseRawHeader'])
|
||||
->setMethods(['getCache','readFirstBlock', 'parseRawHeader'])
|
||||
->getMock();
|
||||
|
||||
$instance->expects($this->once())->method('getCache')->willReturn($cache);
|
||||
|
||||
$instance->expects($this->once())->method(('parseRawHeader'))
|
||||
->willReturn([Util::HEADER_ENCRYPTION_MODULE_KEY => 'OC_DEFAULT_MODULE']);
|
||||
|
||||
|
@ -677,8 +687,8 @@ class EncryptionTest extends Storage {
|
|||
->setMethods(['readFirstBlock', 'parseRawHeader', 'getCache'])
|
||||
->getMock();
|
||||
|
||||
$instance->expects($this->once())->method(('parseRawHeader'))->willReturn($header);
|
||||
$instance->expects($this->any())->method('getCache')->willReturn($cache);
|
||||
$instance->expects($this->any())->method(('parseRawHeader'))->willReturn($header);
|
||||
$instance->expects($this->once())->method('getCache')->willReturn($cache);
|
||||
|
||||
$result = $this->invokePrivate($instance, 'getHeader', ['test.txt']);
|
||||
$this->assertSameSize($expected, $result);
|
||||
|
|
Loading…
Reference in New Issue