PHPOffice / PHPPresentation

A pure PHP library for reading and writing presentations documents
https://phpoffice.github.io/PHPPresentation
Other
1.31k stars 523 forks source link

getimagesizefromstring($imageFile) returns false causing exception when loading presentation #741

Open websuasive opened 1 year ago

websuasive commented 1 year ago

Exception thrown trying to load powerpoint presentation due getimagesizefromstring($imageFile) returning false, rather than a valid array.

(ErrorException(code: 0): Trying to access array offset on value of type bool at /var/www/html/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php:805) [stacktrace]

0 /var/www/html/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php(805): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError()

1 /var/www/html/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php(1372): PhpOffice\PhpPresentation\Reader\PowerPoint2007->loadShapeDrawing()

2 /var/www/html/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php(506): PhpOffice\PhpPresentation\Reader\PowerPoint2007->loadSlideShapes()

3 /var/www/html/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php(396): PhpOffice\PhpPresentation\Reader\PowerPoint2007->loadMasterSlide()

4 /var/www/html/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php(353): PhpOffice\PhpPresentation\Reader\PowerPoint2007->loadMasterSlides()

5 /var/www/html/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php(169): PhpOffice\PhpPresentation\Reader\PowerPoint2007->loadSlides()

6 /var/www/html/vendor/phpoffice/phppresentation/src/PhpPresentation/Reader/PowerPoint2007.php(136): PhpOffice\PhpPresentation\Reader\PowerPoint2007->loadFile()

7 /var/www/html/app/Helpers/ParsePptx.php(35): PhpOffice\PhpPresentation\Reader\PowerPoint2007->load()

Code with issuein PowerPoint2007.php:

$pathImage = implode('/', $pathImage); $imageFile = $this->oZip->getFromName($pathImage); if (!empty($imageFile)) { if ($oShape instanceof Gd) { $info = getimagesizefromstring($imageFile); <============================================= $oShape->setMimeType($info['mime']); $oShape->setRenderingFunction(str_replace('/', '', $info['mime'])); $oShape->setImageResource(imagecreatefromstring($imageFile)); } elseif ($oShape instanceof Base64) { $oShape->setData('data:image/svg+xml;base64,' . base64_encode($imageFile)); } }

websuasive commented 1 year ago

It seems the image causing the problems is one on the slide master layer - and it's an .EMF image.

websuasive commented 1 year ago

See #490 - same problem/feature request.

In the short term, as more people are seeing this - a simple:

if ($info !== false) { $oShape->setMimeType($info['mime']); $oShape->setRenderingFunction(str_replace('/', '', $info['mime'])); $oShape->setImageResource(imagecreatefromstring($imageFile)); }

stops the code from breaking and enables the reader to get the rest of the file.

Is this a permissible fix?

Progi1984 commented 3 months ago

@websuasive Hi, Could you send me a sample file with error, please, for reproducing the bug ?

toto975 commented 2 months ago

Hello, I'm facing the same problem.

Here's is a simple test file. test - Copie.pptx