brechtsanders / xlsxio

XLSX I/O - C library for reading and writing .xlsx files
MIT License
421 stars 112 forks source link

Infinite loop in xlsxio_read.c #123

Open wjeral opened 12 months ago

wjeral commented 12 months ago

Hello, I'm using version 0.2.34. When listing sheets via xlsxioread_list_sheets, in the function iterate_files_by_contenttype_expat_callback_element_start, a callback is called at line 722. The callback function is xlsxioread_list_sheets_callback, which executes expat_process_zip_file.

expat_process_zip_file opens the zip using the referenced zip handle, which results in a file position change. When the callback returns to the iterate function, the file position is moved back to the first file and you end up with an infinite loop.

If fixed it by calling unzGetFilePos prior to the callback and unzGoToFilePos after the callback at line 722 in the iterate function: unz_file_pos pos; (inserted at line 701)

unzGetFilePos (data->zip, &pos); data->filecallbackfn(data->zip, filename, contenttype, data->filecallbackdata); unzGoToFilePos (data->zip, &pos);

BTW, out of hundreds of xlsx files processed, all with varying schemas and layouts, from many different producers, I only have one that hit this particular area of the code in the iterate function. Only one.