Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ precedence = "aggregate"
SPDX-FileCopyrightText = "2025 Nextcloud GmbH and Nextcloud contributors"
SPDX-License-Identifier = "AGPL-3.0-or-later"

[[annotations]]
path = ["tests/data/testimage-disguised-svg.heic"]
precedence = "aggregate"
SPDX-FileCopyrightText = "2026 Nextcloud GmbH and Nextcloud contributors"
SPDX-License-Identifier = "AGPL-3.0-or-later"

[[annotations]]
path = ["composer.json", "composer.lock", ".github/CODEOWNERS", "__tests__/tsconfig.json", "tsconfig.json", "apps/**/composer/composer.json", "apps/**/composer/composer.lock", "apps/**/composer/composer/installed.json"]
precedence = "aggregate"
Expand Down
9 changes: 4 additions & 5 deletions lib/private/Preview/HEIC.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,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();
Expand Down
10 changes: 10 additions & 0 deletions tests/data/testimage-disguised-svg.heic
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
style="overflow: hidden; position: relative;"
width="500"
height="500">
<image x="0" y="0" width="500" height="500" xlink:href="/var/www/html/secret.png" stroke-width="1" id="image3204" />
</svg>
61 changes: 61 additions & 0 deletions tests/lib/Preview/HEICDisguisedSVGTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace Test\Preview;

use OC\Preview\HEIC;

/**
* Class HEICDisguisedSVGTest
*
*
* @package Test\Preview
*/
#[\PHPUnit\Framework\Attributes\Group('DB')]
class HEICDisguisedSVGTest extends Provider {
protected function setUp(): void {
if (!in_array('HEIC', \Imagick::queryFormats('HEI*'))) {
$this->markTestSkipped('ImageMagick is not HEIC aware. Skipping tests');
} else {
parent::setUp();

$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 {
# HEIC->getThumbnail will always return null if there is an exception, be we want to check why getResizedPreview fails
$reflection = new \ReflectionClass($this->provider);
$method = $reflection->getMethod('getResizedPreview');
$method->setAccessible(true);

$absolutePath = \OC::$SERVERROOT . '/tests/data/' . 'testimage-disguised-svg.heic';

try {
$method->invoke(
$this->provider,
$absolutePath,
$this->width,
$this->height
);
$this->fail('Expected ImagickException was not thrown.');
} catch (\ImagickException $e) {
$this->assertStringStartsWith('ImageTypeNotSupported', $e->getMessage());
}
}
}
Loading