]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix: Extend SVG reference check 45340/head
authorJoas Schilling <coding@schilljs.com>
Wed, 15 May 2024 21:38:24 +0000 (23:38 +0200)
committerJoas Schilling <coding@schilljs.com>
Thu, 16 May 2024 08:01:33 +0000 (10:01 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/private/Preview/SVG.php
tests/lib/Preview/SVGTest.php

index 207c9dfb021c0c970b8c1967b990da39c72f0298..0400038d9802c6b0b8c5164168d20b63922125bd 100644 (file)
@@ -50,7 +50,7 @@ class SVG extends ProviderV2 {
                        }
 
                        // Do not parse SVG files with references
-                       if (stripos($content, 'xlink:href') !== false) {
+                       if (preg_match('/["\s](xlink:)?href\s*=/i', $content)) {
                                return null;
                        }
 
index 8764f3a5a9fdc8afc83c895e679d249875a829f2..6a0e93e5f7942ff4e90e72c3300d252e0fabd458 100644 (file)
@@ -29,4 +29,33 @@ class SVGTest extends Provider {
                        $this->markTestSkipped('No SVG provider present');
                }
        }
+
+       public function dataGetThumbnailSVGHref(): array {
+               return [
+                       ['href'],
+                       [' href'],
+                       ["\nhref"],
+                       ['xlink:href'],
+                       [' xlink:href'],
+                       ["\nxlink:href"],
+               ];
+       }
+
+       /**
+        * @dataProvider dataGetThumbnailSVGHref
+        * @requires extension imagick
+        */
+       public function testGetThumbnailSVGHref(string $content): void {
+               $handle = fopen('php://temp', 'w+');
+               fwrite($handle, '<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
+  <image x="0" y="0"' . $content . '="fxlogo.png" height="100" width="100" />
+</svg>');
+               rewind($handle);
+
+               $file = $this->createMock(\OCP\Files\File::class);
+               $file->method('fopen')
+                       ->willReturn($handle);
+
+               self::assertNull($this->provider->getThumbnail($file, 512, 512));
+       }
 }