Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerPoint2007 Reader : Load images from file only if valid #775

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading