diff --git a/docs/changes/1.1.0.md b/docs/changes/1.1.0.md index 45c2e2671d..4f7da78d90 100644 --- a/docs/changes/1.1.0.md +++ b/docs/changes/1.1.0.md @@ -19,6 +19,7 @@ - PowerPoint2077 Writer : Fixed error when defining min/max bounds to 0 - [@LilyEssence](https://github.com/LilyEssence) in [#771](https://github.com/PHPOffice/PHPPresentation/pull/771) - PowerPoint2007 Writer : Outline : Fixed the base unit - [@Pakku](https://github.com/Pakku) in [#772](https://github.com/PHPOffice/PHPPresentation/pull/772) - PowerPoint2007 Writer : Fixed column indices for embedded spreadsheets - [@michael-roth](https://github.com/michael-roth) in [#773](https://github.com/PHPOffice/PHPPresentation/pull/773) +- PowerPoint2007 Reader : Load images from file only if valid - [@aelliott1485](https://github.com/aelliott1485) in [#775](https://github.com/PHPOffice/PHPPresentation/pull/775) ## BC Breaks - `PhpOffice\PhpPresentation\Style\Outline` : the width is now based on pixels (before in points) \ No newline at end of file diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 0ab30292c2..c441265b0c 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -16,6 +16,7 @@ parameters: - '#^Parameter \#1 \$pValue of static method PhpOffice\\Common\\Drawing\:\:pixelsToCentimeters\(\) expects int, float given\.#' - '#^Parameter \#1 \$pValue of static method PhpOffice\\Common\\Drawing\:\:pixelsToEmu\(\) expects int, float given\.#' ## PHP 8.0 & GdImage + - '#^Parameter \#1 \$value of method PhpOffice\\PhpPresentation\\Shape\\Drawing\\Gd::setImageResource\(\) expects resource\|null, GdImage\ given\.#' - '#^Parameter \#1 \$value of method PhpOffice\\PhpPresentation\\Shape\\Drawing\\Gd::setImageResource\(\) expects resource\|null, GdImage\|false given\.#' - '#^Parameter \#1 \$image of function imagesx expects GdImage, resource given\.#' - '#^Parameter \#1 \$image of function imagesy expects GdImage, resource given\.#' diff --git a/src/PhpPresentation/Reader/PowerPoint2007.php b/src/PhpPresentation/Reader/PowerPoint2007.php index dddfc42a85..779009e353 100644 --- a/src/PhpPresentation/Reader/PowerPoint2007.php +++ b/src/PhpPresentation/Reader/PowerPoint2007.php @@ -805,7 +805,11 @@ protected function loadShapeDrawing(XMLReader $document, DOMElement $node, Abstr $info = getimagesizefromstring($imageFile); $oShape->setMimeType($info['mime']); $oShape->setRenderingFunction(str_replace('/', '', $info['mime'])); - $oShape->setImageResource(imagecreatefromstring($imageFile)); + $image = @imagecreatefromstring($imageFile); + if (!$image) { + return; + } + $oShape->setImageResource($image); } elseif ($oShape instanceof Base64) { $oShape->setData('data:image/svg+xml;base64,' . base64_encode($imageFile)); } diff --git a/tests/PhpPresentation/Tests/Reader/PowerPoint2007Test.php b/tests/PhpPresentation/Tests/Reader/PowerPoint2007Test.php index f90b7e7887..202550e88c 100644 --- a/tests/PhpPresentation/Tests/Reader/PowerPoint2007Test.php +++ b/tests/PhpPresentation/Tests/Reader/PowerPoint2007Test.php @@ -615,4 +615,13 @@ public function testSlideLayout(): void self::assertCount(11, $masterSlides[1]->getAllSlideLayouts()); self::assertCount(11, $masterSlides[2]->getAllSlideLayouts()); } + + public function testLoadFileWithInvalidImages(): void + { + $file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/PPTX_InvalidImage.pptx'; + $object = new PowerPoint2007(); + $oPhpPresentation = $object->load($file); + $this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $oPhpPresentation); + $this->assertEquals(1, $oPhpPresentation->getSlideCount()); + } } diff --git a/tests/resources/files/PPTX_InvalidImage.pptx b/tests/resources/files/PPTX_InvalidImage.pptx new file mode 100644 index 0000000000..6b8a398519 Binary files /dev/null and b/tests/resources/files/PPTX_InvalidImage.pptx differ