Skip to content

Attempting to load empty / invalid files throws PHP notices/warnings #1718

Closed
@dregad

Description

This is:

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

What is the expected behavior?

Reader should check return value of failing functions (e.g. ZipArchive::open, simplexml_load_string) and throw some meaningful exception, instead of continuing.

What is the current behavior?

Example with empty xlsx file:

PHP Notice:  Trying to get property 'Relationship' of non-object in /tmp/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php on line 342
PHP Warning:  Invalid argument supplied for foreach() in /tmp/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php on line 342
... etc ...

What are the steps to reproduce?

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:

<?php
include 'vendor/autoload.php';
$xlReader = new PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$xlReader->load('test.xlsx');

Generate an empty or invalid Excel file, e.g. with touch test.xlsx or echo 'hello world' >test.xlsx and run the above script.

Which versions of PhpSpreadsheet and PHP are affected?

Tested on PHP 7.4.3 with PhpSpreadsheet 1.15.0.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions