Libpng crashes to png_write_into (Windows 10, VS2013, self-tuning, all tests pass fine)

I am observing a crash due to access violation in libpng (1.6.20) when calling png_write_info. I created libpng from the source (including zlib 1.2.8), and the png tests that come with the libpng source code fail without errors. I can confirm that during these tests, good png files are created.

A simple breakdown of my program (until it works) looks like this. I removed all error checks and restrictions for simplicity:

int main(int argc, char *argv[]) {
    char* filename = argv[1];
    png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    png_infop info = png_create_info_struct(png);
    if (setjmp(png_jmpbuf(png)))
    {
        abort();
    }

    // Output is 16-bit depth, greyscale format.
    png_set_IHDR(
        png,
        info,
        127, 127,
        16,
        PNG_COLOR_TYPE_GRAY,
        PNG_INTERLACE_NONE,
        PNG_COMPRESSION_TYPE_DEFAULT,
        PNG_FILTER_TYPE_DEFAULT
    );

    // do the file stuff
    FILE *fp;
    errno_t error = fopen_s(&fp, filename, "wb");
    png_init_io(png, fp);
    png_write_info(png, info); // <-- crashes here with "access violation writing location ..."

Thank you for your help!

codeSourcerer

+4
source share
1 answer

, , : libpng png_read_info()

:

Visual Studio , (/MD). - , libpng16.dll, libpng , .

, libpng → → C/++ → → , DLL (/MD) ( )!! png-writer. .

Cheers,
codeSourcerer

+1

Source: https://habr.com/ru/post/1620313/


All Articles