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

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

Open
websuasive opened this issue May 24, 2023 · 4 comments

Comments

@websuasive
Copy link

websuasive commented May 24, 2023

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
Copy link
Author

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

@websuasive
Copy link
Author

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
Copy link
Member

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

@Progi1984 Progi1984 added this to the 1.2.0 milestone Sep 2, 2024
@toto975
Copy link

toto975 commented Sep 2, 2024

Hello,
I'm facing the same problem.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants