viest / php-ext-xlswriter

🚀 PHP Extension for creating and reader XLSX files.
https://xlswriter.viest.me
BSD 2-Clause "Simplified" License
2.26k stars 234 forks source link

nextCellCallback 读取带合并单元格的文件时报 Segmentation fault #201

Closed cfgxy closed 4 years ago

cfgxy commented 4 years ago

nextCellCallback 读取带合并单元格的文件时报 Segmentation fault

版本: PHP 7.2.24 (Docker: php:7.2.24-fpm-buster) xmlwriter 1.3.1 (pecl 方式安装)

Excel结构大致如下:

+------------------+
|      Header      |
+------+-----+-----+
|  K1  |  K2 |  K3 |
+------------------+
|  V1  |  V2 |  V3 |
+------+-----+-----+

读取代码:

<?php
$excel  = new \Vtiful\Kernel\Excel(['path' => '/home/staff']);
$excel->openFile('data.xlsx')
    ->nextCellCallback(function ($row, $cell, $data) {
        var_dump($data);
    });

CoreDump的调用栈:

(gdb) bt
#0  __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:65
#1  0x00007fe0abf07927 in sheet_cell_callback (row=<optimized out>, col=2, value=0x0, callback_data=0x7ffe6fde4e00) at /tmp/pear/temp/xlswriter/kernel/read.c:243
#2  0x00007fe0abf054db in data_sheet_expat_callback_find_cell_end (name=<optimized out>, callbackdata=0x7ffe6fde4d20) at /tmp/pear/temp/xlswriter/library/libxlsxio/lib/xlsxio_read.c:1167
#3  data_sheet_expat_callback_find_cell_end (callbackdata=0x7ffe6fde4d20, name=<optimized out>) at /tmp/pear/temp/xlswriter/library/libxlsxio/lib/xlsxio_read.c:1133
#4  0x00007fe0abef2ad4 in doContent (parser=parser@entry=0x56351fda56a0, startTagLevel=startTagLevel@entry=0, enc=<optimized out>, s=<optimized out>, 
    end=0x56351fda5e30 "erride PartName=\"/xl/workbook.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml\"/><Override PartName=\"/xl/worksheets/sheet1.xml\" ContentType=\"application/vnd"..., nextPtr=0x56351fda56d0, haveMore=1 '\001') at /tmp/pear/temp/xlswriter/library/libexpat/expat/lib/xmlparse.c:2915
#5  0x00007fe0abef3cdc in contentProcessor (parser=0x56351fda56a0, start=<optimized out>, end=<optimized out>, endPtr=<optimized out>) at /tmp/pear/temp/xlswriter/library/libexpat/expat/lib/xmlparse.c:2543
#6  0x00007fe0abef7a58 in XML_ParseBuffer (isFinal=0, len=256, parser=0x56351fda56a0) at /tmp/pear/temp/xlswriter/library/libexpat/expat/lib/xmlparse.c:1979
#7  XML_ParseBuffer (parser=parser@entry=0x56351fda56a0, len=len@entry=256, isFinal=isFinal@entry=0) at /tmp/pear/temp/xlswriter/library/libexpat/expat/lib/xmlparse.c:1948
#8  0x00007fe0abf04ede in expat_process_zip_file (zip=0x56351fc9e370, filename=<optimized out>, start_handler=start_handler@entry=0x7fe0abf05190 <data_sheet_expat_callback_find_worksheet_start>, 
    end_handler=end_handler@entry=0x0, data_handler=data_handler@entry=0x0, callbackdata=callbackdata@entry=0x7ffe6fde4d20, xmlparser=0x7ffe6fde4d20)
    at /tmp/pear/temp/xlswriter/library/libxlsxio/lib/xlsxio_read.c:167
#9  0x00007fe0abf067df in xlsxioread_process (handle=0x56351fda5680, sheetname=<optimized out>, flags=<optimized out>, cell_callback=0x7fe0abf07890 <sheet_cell_callback>, 
    row_callback=0x7fe0abf07460 <sheet_row_callback>, callbackdata=0x7ffe6fde4e00) at /tmp/pear/temp/xlswriter/library/libxlsxio/lib/xlsxio_read.c:1276
#10 0x00007fe0abec99f7 in zim_vtiful_xls_nextCellCallback (execute_data=<optimized out>, return_value=0x7fe0ace1d0a0) at /tmp/pear/temp/xlswriter/kernel/excel.c:933
#11 0x000056351dbfdb54 in execute_ex ()
#12 0x000056351dbfe688 in zend_execute ()
#13 0x000056351db5bfa3 in zend_execute_scripts ()
#14 0x000056351daf95c8 in php_execute_script ()
#15 0x000056351dc00bbe in ?? ()
#16 0x000056351d87f26c in ?? ()
#17 0x00007fe0affa809b in __libc_start_main (main=0x56351d87ede0, argc=2, argv=0x7ffe6fde8918, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7ffe6fde8908)
    at ../csu/libc-start.c:308
#18 0x000056351d87f36a in _start ()

估计可能错在 kernel/read.c 243行的 strlen(value) 调用, value 可能是 null 或者非字符串 https://github.com/viest/php-ext-xlswriter/blob/33ff16f8935ecbc24490a3c8d202d44ca82b3bee/kernel/read.c#L243

viest commented 4 years ago

@cfgxy 如果方便的话,请使用 QQ 添加 readme.md 中的交流群。