Crash in png_set_read_fn() on Windows 7

随声附和 提交于 2019-12-25 05:06:33

问题


I'm cross-compiling some C code for Windows 7 and linking to libpng12.dll found here. Unfortunately, the line below causes a crash (GDB says segmentation fault):

png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);

I'm not sure where to start to debug this--that function seems very straightforward and unrelated to the rest of the code. Top of the backtrace looks like this:

#0 0xabababab in ?? ()
#1 0x6cc556d1 in png_set_read_fn () from c:\...libpng12.dll
#2 0x6cc7a5d4 in png_libpng_ver () from c:\...libpng12.dll
#3 0x00000038 in ?? ()
#4 0x0028f928 in ?? ()

I guess #4 is png_create_read_struct(), since #5 is the function I call it from.


回答1:


Please generate a core dump firstly by using ADplus or windbg etc.., and then look at the assembly code around the address of #0 (0xabababab ), also you can check the variable values with regards to those assembly. If you have the source code, you may have a good chance to understand the logic of why it crashes.




回答2:


Solved (unfortunately by trial & error) but just in case anyone else experiences this issue, it's caused by an incorrect version of zlib (in my case, too old). You can check for this quite easily at runtime:

fprintf(stderr, "   Compiled with libpng %s; using libpng %s.\n",
        PNG_LIBPNG_VER_STRING, png_libpng_ver);
fprintf(stderr, "   Compiled with zlib %s; using zlib %s.\n",
        ZLIB_VERSION, zlib_version);


来源:https://stackoverflow.com/questions/11516870/crash-in-png-set-read-fn-on-windows-7

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!