diff --git a/lib/private/Preview/HEIC.php b/lib/private/Preview/HEIC.php index f2b6cc7254e27..faa5df3d1f70b 100644 --- a/lib/private/Preview/HEIC.php +++ b/lib/private/Preview/HEIC.php @@ -65,6 +65,9 @@ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage { 'app' => 'core', ] ); + if (defined('PHPUNIT_COMPOSER_INSTALL') || defined('__PHPUNIT_PHAR__')) { + throw $e; + } return null; } @@ -96,16 +99,15 @@ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage { private function getResizedPreview($tmpPath, $maxX, $maxY) { $bp = new \Imagick(); - // Some HEIC files just contain (or at least are identified as) other formats - // like JPEG. We just need to check if the image is safe to process. - $bp->pingImage($tmpPath . '[0]'); + // Force Imagick to only accept HEIC or HEIF images + $bp->pingImage('heic:' . $tmpPath . '[0]'); $mimeType = $bp->getImageMimeType(); - if (!preg_match('/^image\/(x-)?(png|jpeg|gif|bmp|tiff|webp|hei(f|c)|avif)$/', $mimeType)) { + if (!preg_match('/^image\/(x-)?hei(f|c)$/', $mimeType)) { throw new \Exception('File mime type does not match the preview provider: ' . $mimeType); } // Layer 0 contains either the bitmap or a flat representation of all vector layers - $bp->readImage($tmpPath . '[0]'); + $bp->readImage('heic:' . $tmpPath . '[0]'); // Fix orientation from EXIF $bp->autoOrient(); diff --git a/tests/data/testimage-disguised-svg.heic b/tests/data/testimage-disguised-svg.heic new file mode 100644 index 0000000000000..28b5988122a80 --- /dev/null +++ b/tests/data/testimage-disguised-svg.heic @@ -0,0 +1,10 @@ + + + + diff --git a/tests/lib/Preview/HEICDisguisedSVGTest.php b/tests/lib/Preview/HEICDisguisedSVGTest.php new file mode 100644 index 0000000000000..f04756794e9e4 --- /dev/null +++ b/tests/lib/Preview/HEICDisguisedSVGTest.php @@ -0,0 +1,51 @@ +markTestSkipped('ImageMagick is not HEIC aware. Skipping tests'); + } else { + parent::setUp(); + + $fileName = 'testimage-disguised-svg.heic'; + $this->imgPath = $this->prepareTestFile($fileName, \OC::$SERVERROOT . '/tests/data/' . $fileName); + $this->width = 1680; + $this->height = 1050; + $this->provider = new HEIC; + } + } + + /** + * Launches all the tests we have + * + * + * @param int $widthAdjustment + * @param int $heightAdjustment + */ + #[\PHPUnit\Framework\Attributes\DataProvider('dimensionsDataProvider')] + #[\PHPUnit\Framework\Attributes\RequiresPhpExtension('imagick')] + public function testGetThumbnail($widthAdjustment, $heightAdjustment): void { + try { + parent::testGetThumbnail($widthAdjustment, $heightAdjustment); + $this->fail('Expected ImagickException was not thrown.'); + } catch (\ImagickException $e) { + $this->assertStringStartsWith('ImageTypeNotSupported', $e->getMessage()); + } + } +}