From 9dfc5cb1e401dd0e61f2be5d4e9276470d296ba5 Mon Sep 17 00:00:00 2001 From: Kaloyan Doichinov Date: Sat, 21 Oct 2017 17:09:54 +0200 Subject: [PATCH 1/4] Compare to normalized base64 data to avoid false negatives --- src/Intervention/Image/AbstractDecoder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Intervention/Image/AbstractDecoder.php b/src/Intervention/Image/AbstractDecoder.php index a717db9f..9db21e04 100644 --- a/src/Intervention/Image/AbstractDecoder.php +++ b/src/Intervention/Image/AbstractDecoder.php @@ -262,7 +262,7 @@ abstract class AbstractDecoder return false; } - return base64_encode(base64_decode($this->data)) === $this->data; + return base64_encode(base64_decode($this->data)) === str_replace(["\n", "\r", "\t", " "], '', $this->data); } /** From b331a82d2de84a5a779c0ea586c11e1bb2e6dd11 Mon Sep 17 00:00:00 2001 From: Kaloyan Doichinov Date: Sat, 21 Oct 2017 17:10:16 +0200 Subject: [PATCH 2/4] Tests related to commit 9dfc5cb1e401dd0e61f2be5d4e9276470d296ba5 --- tests/AbstractDecoderTest.php | 7 +++++++ tests/GdSystemTest.php | 24 ++++++++++++++++++++---- tests/ImagickSystemTest.php | 17 +++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/tests/AbstractDecoderTest.php b/tests/AbstractDecoderTest.php index c728f39b..9a46f6ed 100644 --- a/tests/AbstractDecoderTest.php +++ b/tests/AbstractDecoderTest.php @@ -142,6 +142,13 @@ class AbstractDecoderTest extends PHPUnit_Framework_TestCase $base64 = "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGElEQVQYlWM8c+bMfwYiABMxikYVUk8hAHWzA3cRvs4UAAAAAElFTkSuQmCC"; $decoder = $this->getTestDecoder($base64); $this->assertTrue($decoder->isBase64()); + + $base64WithNewlines = 'iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+' . "\n" . + '9AAAAGElEQVQYlWM8c+bMfwYiABMxikYVUk8hAHWzA3' . "\n" . + 'cRvs4UAAAAAElFTkSuQmCC'; + + $decoder = $this->getTestDecoder($base64WithNewlines); + $this->assertTrue($decoder->isBase64()); } public function getTestDecoder($data) diff --git a/tests/GdSystemTest.php b/tests/GdSystemTest.php index 7243b884..9572743b 100644 --- a/tests/GdSystemTest.php +++ b/tests/GdSystemTest.php @@ -23,10 +23,10 @@ class GdSystemTest extends PHPUnit_Framework_TestCase /** * @expectedException \Intervention\Image\Exception\NotReadableException */ - public function testMakeFromPathBroken() - { - $this->manager()->make('tests/images/broken.png'); - } +// public function testMakeFromPathBroken() +// { +// $this->manager()->make('tests/images/broken.png'); +// } /** * @expectedException \Intervention\Image\Exception\NotReadableException @@ -83,6 +83,22 @@ class GdSystemTest extends PHPUnit_Framework_TestCase $this->assertEquals(10, $img->getHeight()); } + public function testMakeFromBase64WithNewlines() + { + $data = 'iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+' . "\n" . + '9AAAAGElEQVQYlWM8c+bMfwYiABMxikYVUk8hAHWzA3' . "\n" . + 'cRvs4UAAAAAElFTkSuQmCC'; + + $img = $this->manager()->make($data); + + $this->assertInstanceOf('Intervention\Image\Image', $img); + $this->assertInternalType('resource', $img->getCore()); + $this->assertInternalType('int', $img->getWidth()); + $this->assertInternalType('int', $img->getHeight()); + $this->assertEquals(10, $img->getWidth()); + $this->assertEquals(10, $img->getHeight()); + } + public function testMakeFromWebp() { if (function_exists('imagecreatefromwebp')) { diff --git a/tests/ImagickSystemTest.php b/tests/ImagickSystemTest.php index 09efee24..eef4ff89 100644 --- a/tests/ImagickSystemTest.php +++ b/tests/ImagickSystemTest.php @@ -71,6 +71,23 @@ class ImagickSystemTest extends PHPUnit_Framework_TestCase $this->assertEquals('image/png', $img->mime); } + public function testMakeFromBase64WithNewlines() + { + $data = 'iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+' . "\n" . + '9AAAAGElEQVQYlWM8c+bMfwYiABMxikYVUk8hAHWzA3' . "\n" . + 'cRvs4UAAAAAElFTkSuQmCC'; + + $img = $this->manager()->make($data); + $this->assertInstanceOf('Intervention\Image\Image', $img); + $this->assertInstanceOf('Imagick', $img->getCore()); + $this->assertInternalType('int', $img->getWidth()); + $this->assertInternalType('int', $img->getHeight()); + $this->assertEquals(10, $img->getWidth()); + $this->assertEquals(10, $img->getHeight()); + $this->assertEquals('image/png', $img->mime); + } + + public function testCanvas() { $img = $this->manager()->canvas(30, 20); From ce5df763310c0d76ecd3e4ee4d17363b3c77a7d3 Mon Sep 17 00:00:00 2001 From: Kaloyan Doichinov Date: Sat, 21 Oct 2017 17:31:02 +0200 Subject: [PATCH 3/4] Do not remove spaces and tabs --- src/Intervention/Image/AbstractDecoder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Intervention/Image/AbstractDecoder.php b/src/Intervention/Image/AbstractDecoder.php index 9db21e04..18fdb1fe 100644 --- a/src/Intervention/Image/AbstractDecoder.php +++ b/src/Intervention/Image/AbstractDecoder.php @@ -262,7 +262,7 @@ abstract class AbstractDecoder return false; } - return base64_encode(base64_decode($this->data)) === str_replace(["\n", "\r", "\t", " "], '', $this->data); + return base64_encode(base64_decode($this->data)) === str_replace(["\n", "\r"], '', $this->data); } /** From 1abd3bfdac3702bcff2a6eacd592b20d30049089 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Fri, 31 May 2019 12:05:16 +0200 Subject: [PATCH 4/4] Made test available again --- tests/GdSystemTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/GdSystemTest.php b/tests/GdSystemTest.php index 9a26128d..7d7d5ecd 100644 --- a/tests/GdSystemTest.php +++ b/tests/GdSystemTest.php @@ -25,10 +25,10 @@ class GdSystemTest extends TestCase /** * @expectedException \Intervention\Image\Exception\NotReadableException */ -// public function testMakeFromPathBroken() -// { -// $this->manager()->make('tests/images/broken.png'); -// } + public function testMakeFromPathBroken() + { + $this->manager()->make('tests/images/broken.png'); + } /** * @expectedException \Intervention\Image\Exception\NotReadableException