diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2022-01-11 13:35:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-11 13:35:56 +0100 |
commit | c47406ad3cc1606d7357af6c32c4fa7dd0ac53a7 (patch) | |
tree | 77f9931990cd270451f9f738e14bb852704f26f2 /tests | |
parent | b23934a45ec584e398835635584461a02c9b1dde (diff) | |
parent | d3d65e5c889fc3922efc7a8c764027763bc4764f (diff) | |
download | nextcloud-server-c47406ad3cc1606d7357af6c32c4fa7dd0ac53a7.tar.gz nextcloud-server-c47406ad3cc1606d7357af6c32c4fa7dd0ac53a7.zip |
Merge pull request #30291 from nextcloud/image-memory-limit
Prevent loading images that would require too much memory.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/data/testimage-badheader.jpg | bin | 0 -> 103 bytes | |||
-rw-r--r-- | tests/lib/ImageTest.php | 17 |
2 files changed, 17 insertions, 0 deletions
diff --git a/tests/data/testimage-badheader.jpg b/tests/data/testimage-badheader.jpg Binary files differnew file mode 100644 index 00000000000..b876804eb4e --- /dev/null +++ b/tests/data/testimage-badheader.jpg diff --git a/tests/lib/ImageTest.php b/tests/lib/ImageTest.php index 5b83c4ac57f..e6818c7e243 100644 --- a/tests/lib/ImageTest.php +++ b/tests/lib/ImageTest.php @@ -142,6 +142,10 @@ class ImageTest extends \Test\TestCase { ->method('getAppValue') ->with('preview', 'jpeg_quality', 90) ->willReturn(null); + $config->expects($this->once()) + ->method('getSystemValueInt') + ->with('preview_max_memory', 128) + ->willReturn(128); $img = new \OC_Image(null, null, $config); $img->loadFromFile(OC::$SERVERROOT.'/tests/data/testimage.jpg'); $raw = imagecreatefromstring(file_get_contents(OC::$SERVERROOT.'/tests/data/testimage.jpg')); @@ -363,4 +367,17 @@ class ImageTest extends \Test\TestCase { $img->save($tempFile, $mimeType); $this->assertEquals($mimeType, image_type_to_mime_type(exif_imagetype($tempFile))); } + + public function testMemoryLimitFromFile() { + $img = new \OC_Image(); + $img->loadFromFile(OC::$SERVERROOT.'/tests/data/testimage-badheader.jpg'); + $this->assertFalse($img->valid()); + } + + public function testMemoryLimitFromData() { + $data = file_get_contents(OC::$SERVERROOT.'/tests/data/testimage-badheader.jpg'); + $img = new \OC_Image(); + $img->loadFromData($data); + $this->assertFalse($img->valid()); + } } |