Skip to content

Commit

Permalink
Merge pull request #775 from Progi1984/pr707
Browse files Browse the repository at this point in the history
PowerPoint2007 Reader : Load images from file only if valid
  • Loading branch information
Progi1984 authored Dec 5, 2023
2 parents a8db2bf + afe9459 commit 1aa28c4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changes/1.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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\.#'
Expand Down
6 changes: 5 additions & 1 deletion src/PhpPresentation/Reader/PowerPoint2007.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
9 changes: 9 additions & 0 deletions tests/PhpPresentation/Tests/Reader/PowerPoint2007Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
self::assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $oPhpPresentation);
self::assertEquals(1, $oPhpPresentation->getSlideCount());
}
}
Binary file added tests/resources/files/PPTX_InvalidImage.pptx
Binary file not shown.

0 comments on commit 1aa28c4

Please sign in to comment.