iliaal / php_excel

PHP Extension interface to the Excel writing/reading library
http://ilia.ws
533 stars 131 forks source link

Excelsheet::readRow() causes Apache error AH00051 #254

Closed edreg closed 3 years ago

edreg commented 4 years ago

Hello,

I'm a big fan of your software. I guess I found a small bug:

In my database there was a time entry (‘0070-12-02‘) which was formatted as a date in the Libxl export. When re-importing, this causes the Libxl function (Excelsheet::readRow()) to crash severely. Named as AH00051 in the Apache log.

[xxx] [core:notice] [pid xxx] AH00051: child pid xxx exit signal Segmentation fault (11), possible coredump in /etc/apache2

I'm running PHP 7.2 / CentOS / Apache 2.4

example.xlsx

johmue commented 4 years ago

I tried your file and I "only" get a PHP Warning which forwards the libxl error "custom number format not found"... on the other hand I tested with PHP 7.3 / Win / cmd

edreg commented 4 years ago

libxl.zip

Hey johmue,

You're right, the example was bad. It took me some time to reproduce the problem. I suspect, however, that it also exists under Windows and PHP 7.3.

I have now attached an executable example. With me the server steers about 10 times into the index.php before it lubricates.

johmue commented 4 years ago

Unfortunately I did not receive any values from your file which might make sense since the custom number format issue is still present and breaks the readRow() at all:

$excelBook = new \ExcelBook(null, null, true);
$excelBook->setLocale('UTF-8');
$excelBook->loadFile('example.xlsx');

$sheet = $excelBook->getSheet($excelBook->getActiveSheet());

var_dump($sheet->read(1,1)); // works
var_dump($sheet->read(1,2)); // breaks

I would recommend to not use readRow() for the moment and use read() on cell level instead, there you get at least meaningful error messages:

$data = [];
for ($row=$sheet->firstRow(); $row <= $sheet->lastRow(); $row++) {
    for ($col=$sheet->firstCol(); $col <= $sheet->lastCol(); $col++) {
        $data[$row][$col] = $sheet->read($row, $col);
    }
}
edreg commented 4 years ago

I think the problem is with libxl, which writes a very early date ('0070-12-02') as '-668056,004537037' into the cell's value, but marks it as date formatted or something like that. However, my workaround is to intercept and normalize these early dates beforehand.

I have also contacted libxl about this by mail.