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

Notice and error when reading .xls (BIFF8) having invalid xfIndex #1238

Closed
dendemann opened this issue Nov 13, 2019 · 1 comment
Closed

Notice and error when reading .xls (BIFF8) having invalid xfIndex #1238

dendemann opened this issue Nov 13, 2019 · 1 comment

Comments

@dendemann
Copy link

dendemann commented Nov 13, 2019

This is:

- [x] a bug report
- [ ] a feature request
- [x] not a usage question

What is the expected behavior?

Reading an Excel 97-2003 document shouldn't throw notices or errors.

What is the current behavior?

Reading an Excel 97-2003 documents isn't possible when the data is corrupted in a certain way.

What are the steps to reproduce?

Legacy .xls documents created with third party libraries might contain corrupt data. In my case xfIndex read from a cell is 0 while there's only one entry within the mapCellXfIndex mapping array at index position 15. Therefore there will be an unchecked array access at pos 0.

Unfortunately I can't provide the file as it contains sensitive customer data. But I found out that, according to the shared strings table (sst), it was originally created by the library "GemBox.Spreadsheet Professional 3.3 for .NET 4.0, Version=33.3.40.1062".

Another guy ran into the same problem but I think no one was looking into it: 432120730

Reading the file with Excel or LibreOffice works without problems.

<?php

use PhpOffice\PhpSpreadsheet\Reader\Xls;

require __DIR__ . '/vendor/autoload.php';

$reader = new Xls();
$spreadsheet = $reader->load(__DIR__ . '/broken.xls');

$cell = $spreadsheet->getActiveSheet()->getCell('A1');
var_dump($cell->getFormattedValue());
PHP Notice:  Undefined offset: 0 in /home/user/test/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xls.php on line 3830
PHP Stack trace:
PHP   1. {main}() /home/user/test/test.php:0
PHP   2. PhpOffice\PhpSpreadsheet\Reader\Xls->load() /home/user/test/test.php:8
PHP   3. PhpOffice\PhpSpreadsheet\Reader\Xls->readLabelSst() /home/user/test/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xls.php:956
PHP Notice:  Undefined index:  in /home/user/test/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Spreadsheet.php on line 1034
PHP Stack trace:
PHP   1. {main}() /home/user/test/test.php:0
PHP   2. PhpOffice\PhpSpreadsheet\Cell\Cell->getFormattedValue() /home/user/test/test.php:11
PHP   3. PhpOffice\PhpSpreadsheet\Style\NumberFormat->getFormatCode() /home/user/test/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Cell.php:167
PHP   4. PhpOffice\PhpSpreadsheet\Style\NumberFormat->getSharedComponent() /home/user/test/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Style/NumberFormat.php:165
PHP   5. PhpOffice\PhpSpreadsheet\Style\Style->getSharedComponent() /home/user/test/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Style/NumberFormat.php:112
PHP   6. PhpOffice\PhpSpreadsheet\Spreadsheet->getCellXfByIndex() /home/user/test/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Style/Style.php:124
PHP Fatal error:  Uncaught Error: Call to a member function getNumberFormat() on null in /home/user/test/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Style/NumberFormat.php:112
Stack trace:
#0 /home/user/test/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Style/NumberFormat.php(165): PhpOffice\PhpSpreadsheet\Style\NumberFormat->getSharedComponent()
#1 /home/user/test/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Cell.php(167): PhpOffice\PhpSpreadsheet\Style\NumberFormat->getFormatCode()
#2 /home/user/test/test.php(11): PhpOffice\PhpSpreadsheet\Cell\Cell->getFormattedValue()
#3 {main}
  thrown in /home/user/test/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Style/NumberFormat.php on line 112

Which versions of PhpSpreadsheet and PHP are affected?

At least the following: 1.6.0, 1.9.0 (current)

@PowerKiKi
Copy link
Member

Fixed via #1239

@oleibman oleibman mentioned this issue Jun 15, 2020
5 tasks
MarkBaker pushed a commit that referenced this issue Jun 19, 2020
This problem is the same as #1238, which was resolved by #1239.
For that issue, the fix was to check in one place whether
$this->mapCellXfIndex[$xfIndex] was set before using it.
The sample spreadsheet supplied as a description for this
problem had exactly the same problem in 2 other places in the code.
In addition, there were 7 other places in the code where that
particular item was used unchecked. This fix corrects all 9 locations.
The spreadsheet supplied with the problem is used as the basis
for some new tests, which particularly test column dimensions
and styles, the problems involved in this case.
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