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

Crash on embedded objects #1791

Closed
1210mk2 opened this issue Jan 14, 2021 · 1 comment
Closed

Crash on embedded objects #1791

1210mk2 opened this issue Jan 14, 2021 · 1 comment

Comments

@1210mk2
Copy link

1210mk2 commented Jan 14, 2021

This is:

- [x] a bug report
- [ ] a feature request
- [x] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

parse correctly

What is the current behavior?

crashes with error 'Undefined index'

What are the steps to reproduce?

If you put object to xls cell without (i suppose) a picture

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

please explore
src/PhpSpreadsheet/Reader/Xlsx.php
the string #1611 (on 1.0 ver, latest should be different)
the code around there is:

foreach ($xmlDrawing->twoCellAnchor as $twoCellAnchor) {
    if ($twoCellAnchor->pic->blipFill) {
        $blip = $twoCellAnchor->pic->blipFill->children('http://schemas.openxmlformats.org/drawingml/2006/main')->blip;
        $xfrm = $twoCellAnchor->pic->spPr->children('http://schemas.openxmlformats.org/drawingml/2006/main')->xfrm;
        $outerShdw = $twoCellAnchor->pic->spPr->children('http://schemas.openxmlformats.org/drawingml/2006/main')->effectLst->outerShdw;
        $objDrawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
        $objDrawing->setName((string) self::getArrayItem($twoCellAnchor->pic->nvPicPr->cNvPr->attributes(), 'name'));
        $objDrawing->setDescription((string) self::getArrayItem($twoCellAnchor->pic->nvPicPr->cNvPr->attributes(), 'descr'));
        $objDrawing->setPath(
            'zip://' . File::realpath($pFilename) . '#' .
            $images[(string) self::getArrayItem(
                $blip->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'),
                'embed'
            )],
            false
        );

in $objDrawing->setPath there's a $images[(string) self::getArrayItem(...)]. And in my case self::getArrayItem(...) gives null, then (string) null gives empty string, and $images[""] crashes the code.

Please make a patch which prevents this, eg by isset() functionality.
Thanks!

Which versions of PhpSpreadsheet and PHP are affected?

tested on 1.0 and latest

@oleibman
Copy link
Collaborator

Suggested code change was made in PR #1970, which was merged in April 2021.

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

No branches or pull requests

2 participants