PHPPresentation icon indicating copy to clipboard operation
PHPPresentation copied to clipboard

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

Open websuasive opened this issue 2 years ago • 4 comments

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 avatar May 24 '23 13:05 websuasive

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

websuasive avatar May 24 '23 14:05 websuasive

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?

websuasive avatar May 24 '23 15:05 websuasive

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

Progi1984 avatar Aug 21 '24 21:08 Progi1984