Skip to content
Snippets Groups Projects
Commit bc76058e authored by Remo Häusler's avatar Remo Häusler Committed by Susanne Moog
Browse files

[BUGFIX] Prevent throwing warnings when extract svg image sizes

TYPO3 should silently ignore errors and warnings in svg images.

Resolves: #86428
Releases: master, 9.5, 8.7
Change-Id: I54bb19ac0a6c949a8b150808f52562b73653e739
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/59802


Tested-by: default avatarDaniel Goerz <daniel.goerz@posteo.de>
Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: default avatarSusanne Moog <look@susi.dev>
Reviewed-by: default avatarDaniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: default avatarJörg Bösche <typo3@joergboesche.de>
Reviewed-by: default avatarSusanne Moog <look@susi.dev>
parent ae6936dd
Branches
Tags
No related merge requests found
......@@ -120,7 +120,7 @@ class ImageInfo extends FileInfo implements LoggerAwareInterface
$fileContent = file_get_contents($this->getPathname());
// Disables the functionality to allow external entities to be loaded when parsing the XML, must be kept
$previousValueOfEntityLoader = libxml_disable_entity_loader(true);
$xml = simplexml_load_string($fileContent, 'SimpleXMLElement', LIBXML_NOERROR);
$xml = simplexml_load_string($fileContent, 'SimpleXMLElement', LIBXML_NOERROR | LIBXML_NOWARNING);
// If something went wrong with simpleXml don't try to read information
if ($xml === false) {
......
......@@ -38,14 +38,51 @@ class ImageInfoTest extends UnitTestCase
$this->assertInstanceOf($className, $classInstance);
}
/**
* @return array
*/
public function doesNotBreakOnImageInfoWithInvalidSvgDataProvider(): array
{
return [
['Invalid XML.', 0, 0],
[
'<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" [
<!ENTITY ns_a "http://ns.typo3.com/test/a/1.0/">
<!ENTITY ns_b "http://ns.typo3.com/test/b/1.0/">
]>
<svg version="1.0"
xmlns:x="&ns_a;"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xml:space="preserve"
x="0px" y="0px" viewBox="0 0 436 177">
<metadata>
<sfw xmlns="&ns_b;">
<slices></slices>
</sfw>
</metadata>
</svg>',
436,
177
],
];
}
/**
* @test
* @dataProvider doesNotBreakOnImageInfoWithInvalidSvgDataProvider
* @param string $svg
* @param int $width
* @param int $height
*/
public function doesNotBreakOnImageInfoWithInvalidSvg()
public function doesNotBreakOnImageInfoWithInvalidSvg($svg, $width, $height)
{
$this->resetSingletonInstances = true;
$root = vfsStream::setup('root');
$testFile = 'test.svg';
vfsStream::newFile($testFile)->at($root)->setContent('Invalid XML.');
vfsStream::newFile($testFile)->at($root)->setContent($svg);
$GLOBALS['TYPO3_CONF_VARS']['SYS']['FileInfo']['fileExtensionToMimeType'] = [
'svg' => 'image/svg+xml',
......@@ -62,8 +99,10 @@ class ImageInfoTest extends UnitTestCase
$imageInfo = new ImageInfo($root->url() . '/' . $testFile);
$imageInfo->setLogger($loggerProphecy->reveal());
$this->assertEquals(0, $imageInfo->getWidth());
$this->assertEquals(0, $imageInfo->getHeight());
$this->assertSame($width, $imageInfo->getWidth());
$this->assertSame($height, $imageInfo->getHeight());
GeneralUtility::makeInstance(GraphicalFunctions::class);
}
/**
......@@ -81,6 +120,9 @@ class ImageInfoTest extends UnitTestCase
/**
* @test
* @dataProvider canDetectImageSizesDataProvider
* @param string $file
* @param int $width
* @param int $height
*/
public function canDetectImageSizes($file, $width, $height)
{
......@@ -88,7 +130,7 @@ class ImageInfoTest extends UnitTestCase
$imageInfo = new ImageInfo(__DIR__ . '/../Fixture/' . $file);
$imageInfo->setLogger($logger);
$this->assertEquals($width, $imageInfo->getWidth());
$this->assertEquals($height, $imageInfo->getHeight());
$this->assertSame($width, $imageInfo->getWidth());
$this->assertSame($height, $imageInfo->getHeight());
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment