Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPEG parameter struct mismatch

Tags:

c

struct

libjpeg

Ater compiling libjpeg and then using it, I stumbled upon the problem:

JPEG parameter struct mismatch: library thinks size is 512, caller expects 492

after which the program halts. This happens specifically with the structs struct jpeg_decompress_struct and struct jpeg_compress_struct. If the checks are removed on these structs, the program crashes with a null pointer exception, and the struct members contain garbage.

The error occurs with either precompiled binaries from version 6b, or with precompiled version 9a, and with the compiled version 9a; compiled with MinGW, MSYS 1.0, on windows (32 bit). Messing around in the config files does not help; the number 492 can change, but never equals 512 in order for the program to function.

The libjpeg compilation did create a valid cjpeg.exe and djpeg.exe.

Any ideas?

like image 633
user3F31A28 Avatar asked Apr 07 '14 23:04

user3F31A28


1 Answers

In my case, the problem was that the library and my program were compiled with different values of HAVE_BOOLEAN, so boolean type had different size.

Library was compiled with HAVE_BOOLEAN not defined, so it was using int as defined in libjpeg. Program was compiled with HAVE_BOOLEAN defined, and because some other headers were included before libjpeg, it was using unsigned char as defined in Windows RTL.

Reason I used HAVE_BOOLEAN was to fix compile error about this, but it then caused a linker error. Instead, the proper solution was to not include Windows RTL (or any file that includes it) in the file that uses libjpeg.

like image 151
VLL Avatar answered Oct 14 '22 23:10

VLL