Skip to content

Commit afe9459

Browse files
aelliott-atlasProgi1984
authored andcommitted
PowerPoint2007 Reader : Load images from file only if valid
1 parent a8db2bf commit afe9459

File tree

5 files changed

+16
-1
lines changed

5 files changed

+16
-1
lines changed

docs/changes/1.1.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- 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)
2020
- PowerPoint2007 Writer : Outline : Fixed the base unit - [@Pakku](https://github.com/Pakku) in [#772](https://github.com/PHPOffice/PHPPresentation/pull/772)
2121
- PowerPoint2007 Writer : Fixed column indices for embedded spreadsheets - [@michael-roth](https://github.com/michael-roth) in [#773](https://github.com/PHPOffice/PHPPresentation/pull/773)
22+
- PowerPoint2007 Reader : Load images from file only if valid - [@aelliott1485](https://github.com/aelliott1485) in [#775](https://github.com/PHPOffice/PHPPresentation/pull/775)
2223

2324
## BC Breaks
2425
- `PhpOffice\PhpPresentation\Style\Outline` : the width is now based on pixels (before in points)

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ parameters:
1616
- '#^Parameter \#1 \$pValue of static method PhpOffice\\Common\\Drawing\:\:pixelsToCentimeters\(\) expects int, float given\.#'
1717
- '#^Parameter \#1 \$pValue of static method PhpOffice\\Common\\Drawing\:\:pixelsToEmu\(\) expects int, float given\.#'
1818
## PHP 8.0 & GdImage
19+
- '#^Parameter \#1 \$value of method PhpOffice\\PhpPresentation\\Shape\\Drawing\\Gd::setImageResource\(\) expects resource\|null, GdImage\ given\.#'
1920
- '#^Parameter \#1 \$value of method PhpOffice\\PhpPresentation\\Shape\\Drawing\\Gd::setImageResource\(\) expects resource\|null, GdImage\|false given\.#'
2021
- '#^Parameter \#1 \$image of function imagesx expects GdImage, resource given\.#'
2122
- '#^Parameter \#1 \$image of function imagesy expects GdImage, resource given\.#'

src/PhpPresentation/Reader/PowerPoint2007.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,11 @@ protected function loadShapeDrawing(XMLReader $document, DOMElement $node, Abstr
805805
$info = getimagesizefromstring($imageFile);
806806
$oShape->setMimeType($info['mime']);
807807
$oShape->setRenderingFunction(str_replace('/', '', $info['mime']));
808-
$oShape->setImageResource(imagecreatefromstring($imageFile));
808+
$image = @imagecreatefromstring($imageFile);
809+
if (!$image) {
810+
return;
811+
}
812+
$oShape->setImageResource($image);
809813
} elseif ($oShape instanceof Base64) {
810814
$oShape->setData('data:image/svg+xml;base64,' . base64_encode($imageFile));
811815
}

tests/PhpPresentation/Tests/Reader/PowerPoint2007Test.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,4 +615,13 @@ public function testSlideLayout(): void
615615
self::assertCount(11, $masterSlides[1]->getAllSlideLayouts());
616616
self::assertCount(11, $masterSlides[2]->getAllSlideLayouts());
617617
}
618+
619+
public function testLoadFileWithInvalidImages(): void
620+
{
621+
$file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/PPTX_InvalidImage.pptx';
622+
$object = new PowerPoint2007();
623+
$oPhpPresentation = $object->load($file);
624+
self::assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $oPhpPresentation);
625+
self::assertEquals(1, $oPhpPresentation->getSlideCount());
626+
}
618627
}
1.14 MB
Binary file not shown.

0 commit comments

Comments
 (0)