From 69f977b7265eb5169c5d9c4375b9251cd33be9b8 Mon Sep 17 00:00:00 2001 From: zema Date: Tue, 26 Apr 2016 11:48:25 +0300 Subject: [PATCH] throw NotReadableException if try read partially saved image (getimagesize returns correct size, but image infact is not readable) --- src/Intervention/Image/Gd/Decoder.php | 17 +++++++++++------ tests/GdSystemTest.php | 8 ++++++++ tests/images/broken.png | Bin 0 -> 42 bytes 3 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 tests/images/broken.png diff --git a/src/Intervention/Image/Gd/Decoder.php b/src/Intervention/Image/Gd/Decoder.php index 13fb8f3b..5525b4dd 100644 --- a/src/Intervention/Image/Gd/Decoder.php +++ b/src/Intervention/Image/Gd/Decoder.php @@ -25,18 +25,15 @@ class Decoder extends \Intervention\Image\AbstractDecoder // define core switch ($info[2]) { case IMAGETYPE_PNG: - $core = imagecreatefrompng($path); - $this->gdResourceToTruecolor($core); + $core = @imagecreatefrompng($path); break; case IMAGETYPE_JPEG: - $core = imagecreatefromjpeg($path); - $this->gdResourceToTruecolor($core); + $core = @imagecreatefromjpeg($path); break; case IMAGETYPE_GIF: - $core = imagecreatefromgif($path); - $this->gdResourceToTruecolor($core); + $core = @imagecreatefromgif($path); break; default: @@ -45,6 +42,14 @@ class Decoder extends \Intervention\Image\AbstractDecoder ); } + if ($core === false) { + throw new \Intervention\Image\Exception\NotReadableException( + "Unable to read image from file ({$path})." + ); + } + + $this->gdResourceToTruecolor($core); + // build image $image = $this->initFromGdResource($core); $image->mime = $info['mime']; diff --git a/tests/GdSystemTest.php b/tests/GdSystemTest.php index 5fdcd339..318a6446 100644 --- a/tests/GdSystemTest.php +++ b/tests/GdSystemTest.php @@ -20,6 +20,14 @@ class GdSystemTest extends PHPUnit_Framework_TestCase $this->assertEquals('image/png', $img->mime); } + /** + * @expectedException \Intervention\Image\Exception\NotReadableException + */ + public function testMakeFromPathBroken() + { + $this->manager()->make('tests/images/broken.png'); + } + public function testMakeFromString() { $str = file_get_contents('tests/images/circle.png'); diff --git a/tests/images/broken.png b/tests/images/broken.png new file mode 100644 index 0000000000000000000000000000000000000000..eaecd5c64023152ca7c424acf044cff4fe93b068 GIT binary patch literal 42 vcmeAS@N?(olHy`uVBq!ia0voZz6=a3NgQkp42-e*>=zjr6c{{R97DJOiY*3R literal 0 HcmV?d00001