brechtsanders / xlsxio

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

xlsxioread_open_memory @ xlsxio-0.2.34-binary-win64.zip, crash when freedata is not zero #125

Closed stupid0319 closed 7 months ago

stupid0319 commented 7 months ago

using in cygwin xlsxioread_open_memory , param freedata not zero will crash, I think zip_source_buffer_create has a bug.

brechtsanders commented 7 months ago

Can you please post minimal reproducible code?

Have you tried to debug with gdb to find out where it crashes?

Also please try to build with WITH_LIBZIP so we can establish it's not an issue inside Minizip?

stupid0319 commented 7 months ago
S32 fileLength = 0;
S8 *sourceFile = readFile(filename, &fileLength);
if (sourceFile == NULL)
{
    MessageBox(NULL, filename, "Error opening .xlsx file@1", MB_OK);
    return 0;
}
if ((xlsxioread = xlsxioread_open_memory(sourceFile, fileLength, 1)) == NULL)
{
    free(sourceFile);
    MessageBox(NULL, filename, "Error opening .xlsx file@2", MB_OK);
    return 0;
}

xlsxioread_close(xlsxioread);
//free(sourceFile);

this code only crash when xlsxioread_open_memory freedata = 1, I tried use ollydbg to debug, but can't attach, xlsxio-0.2.34-binary-win64.zip is just download from github release, https://github.com/brechtsanders/xlsxio/releases I will try gdb.

stupid0319 commented 7 months ago

warning: Critical error detected c0000374

Thread 1 "shopeeplp" received signal SIGTRAP, Trace/breakpoint trap. 0x00007ffc7121c733 in ntdll!RtlIsZeroMemory () from /cygdrive/c/Windows/SYSTEM32/ntdll.dll (gdb) backtrace

0 0x00007ffc7121c733 in ntdll!RtlIsZeroMemory () from /cygdrive/c/Windows/SYSTEM32/ntdll.dll

1 0x00007ffc7122580a in ntdll!.misaligned_access () from /cygdrive/c/Windows/SYSTEM32/ntdll.dll

2 0x00007ffc71225aea in ntdll!.misaligned_access () from /cygdrive/c/Windows/SYSTEM32/ntdll.dll

3 0x00007ffc71231ae5 in ntdll!.misaligned_access () from /cygdrive/c/Windows/SYSTEM32/ntdll.dll

4 0x00007ffc7114becc in ntdll!RtlGetCurrentServiceSessionId () from /cygdrive/c/Windows/SYSTEM32/ntdll.dll

5 0x00007ffc7114ab11 in ntdll!RtlFreeHeap () from /cygdrive/c/Windows/SYSTEM32/ntdll.dll

6 0x00007ffc6f6dcadc in msvcrt!free () from /cygdrive/c/Windows/System32/msvcrt.dll

7 0x00007ffc4f3e16d8 in ?? () from /cygdrive/c/src/shopeePackingListPrinter/shopeeplp/mbin/libxlsxio_read.dll

8 0x00007ffc4f3e7987 in xlsxioread_free () from /cygdrive/c/src/shopeePackingListPrinter/shopeeplp/mbin/libxlsxio_read.dll

9 0x00007ffc4f3e3a65 in xlsxioread_close () from /cygdrive/c/src/shopeePackingListPrinter/shopeeplp/mbin/libxlsxio_read.dll

10 0x0000000100401ee1 in ?? ()

11 0x0000000100403199 in ?? ()

12 0x00007ffc70f18241 in USER32!DispatchMessageW () from /cygdrive/c/Windows/System32/USER32.dll

13 0x00007ffc70f1776d in USER32!SendMessageW () from /cygdrive/c/Windows/System32/USER32.dll

14 0x00007ffc70f17527 in USER32!SendMessageW () from /cygdrive/c/Windows/System32/USER32.dll

15 0x00007ffc70f461fd in USER32!SetCursorContents () from /cygdrive/c/Windows/System32/USER32.dll

16 0x00007ffc70f3f372 in USER32!GetWindowTextLengthA () from /cygdrive/c/Windows/System32/USER32.dll

17 0x00007ffc70f45614 in USER32!SetCursorContents () from /cygdrive/c/Windows/System32/USER32.dll

18 0x00007ffc70f18241 in USER32!DispatchMessageW () from /cygdrive/c/Windows/System32/USER32.dll

19 0x00007ffc70f17d01 in USER32!DispatchMessageW () from /cygdrive/c/Windows/System32/USER32.dll

20 0x0000000100404416 in ?? ()

21 0x000000010048f225 in ?? ()

22 0x00007ffc243c80a3 in cygwin_dll_init () from /usr/bin/cygwin1.dll

23 0x00007ffc243c5c86 in cygwin1!.assert () from /usr/bin/cygwin1.dll

24 0x00007ffc243c5d34 in cygwin1!.assert () from /usr/bin/cygwin1.dll

25 0x0000000000000000 in ?? ()

Backtrace stopped: previous frame inner to this frame (corrupt stack?)

stupid0319 commented 7 months ago

I think malloc of cygwin (use unix api) and malloc of windows (use win api) is not same function, so malloc in cygwin and free in winapi will do this error. thinks for reply

brechtsanders commented 7 months ago

Did you debug a static build?

The downloadable binaries are for MinGW-w64, not Cygwin.

Please don't mix target platforms within your builds. Their malloc() will definitely be different and incompatible!

If you want to use it from Cygwin, build with Cygwin from source.

In general when targetting Windows it's best to aim for native (MinGW-w64) builds.