QImage::fromData SEGV
-
I am trying to create a
QImageform aQByteArrayusingQImage::fromDatabut I run into an error here in jdapimin.c:GLOBAL(void) jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize) { ... if (version != JPEG_LIB_VERSION) ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version); ...The same code works just fine on a different machine. Is there a library that is non up to date on my system or why do I run into this error?
(I am on Manjaro Linux) -
I am trying to create a
QImageform aQByteArrayusingQImage::fromDatabut I run into an error here in jdapimin.c:GLOBAL(void) jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize) { ... if (version != JPEG_LIB_VERSION) ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version); ...The same code works just fine on a different machine. Is there a library that is non up to date on my system or why do I run into this error?
(I am on Manjaro Linux)@Creaperdown
And what error do you run into where from what?
If you calljpeg_CreateDecompress()what parameters do you pass in?
If you passJPEG_LIB_VERSIONthen the implication is the one you have included for compiling does not match the one the library was compiled with. -
@Creaperdown
And what error do you run into where from what?
If you calljpeg_CreateDecompress()what parameters do you pass in?
If you passJPEG_LIB_VERSIONthen the implication is the one you have included for compiling does not match the one the library was compiled with.@JonB I am not calling the above function directly. I am calling
QImage::fromDatawhich leads to a crash, stopping in this function. -
@JonB I am not calling the above function directly. I am calling
QImage::fromDatawhich leads to a crash, stopping in this function.@Creaperdown
I see. Then my question should have been "what parameters are passed to it from whatever calls it".Since it SEGVs if you run under debugger it should break at that statement. Depending on how it was compiled debug-wise, try to see what the value of
versionis. You may not be able to viewJPEG_LIB_VERSION's value as it's probably a#define, but you could always drop into the generated assembler to see what two values are being compared.I don't know whether
versioncomes from something inside the actual file being read or (more likely?) is compiled-in for the version of the JPEG decompressor library being used. It is clearly supposed to be the same as whateverJPEG_LIB_VERSIONis. Assuming it comes from compiled code, I don't know whether the JPEG library is statically- or dynamically-compiled but could one machine be picking up a different version of this library than intended/the other machine does? -
@Creaperdown
I see. Then my question should have been "what parameters are passed to it from whatever calls it".Since it SEGVs if you run under debugger it should break at that statement. Depending on how it was compiled debug-wise, try to see what the value of
versionis. You may not be able to viewJPEG_LIB_VERSION's value as it's probably a#define, but you could always drop into the generated assembler to see what two values are being compared.I don't know whether
versioncomes from something inside the actual file being read or (more likely?) is compiled-in for the version of the JPEG decompressor library being used. It is clearly supposed to be the same as whateverJPEG_LIB_VERSIONis. Assuming it comes from compiled code, I don't know whether the JPEG library is statically- or dynamically-compiled but could one machine be picking up a different version of this library than intended/the other machine does?@JonB
versionis 80 for me. I'll try finding theJPEG_LIB_VERSION#define -
@JonB
versionis 80 for me. I'll try finding theJPEG_LIB_VERSION#define@Creaperdown hi,
Out of curiosity, why are you using the JPEG library since Qt already has an image plugin for that format ?
-
@Creaperdown hi,
Out of curiosity, why are you using the JPEG library since Qt already has an image plugin for that format ?
@SGaist The OP is using QImage::fromData() and the result is a crash in the code embedded/called within the plugin. IIRC this JPEG code may be embedded in Qt or from a system library.
My money is on passing an invalid buffer or size to the QImage function in the first place. "Works just fine on a different machine" is not a good reference if, for example, the buffer is a deleted temporary object that gets overwritten, or written to by an unsynchronised thread... these all come down to matters of timing and system load.
-
@SGaist The OP is using QImage::fromData() and the result is a crash in the code embedded/called within the plugin. IIRC this JPEG code may be embedded in Qt or from a system library.
My money is on passing an invalid buffer or size to the QImage function in the first place. "Works just fine on a different machine" is not a good reference if, for example, the buffer is a deleted temporary object that gets overwritten, or written to by an unsynchronised thread... these all come down to matters of timing and system load.
@ChrisW67 Is there a way that I could test if that buffer contains valid data?
-
@ChrisW67 Is there a way that I could test if that buffer contains valid data?
@Creaperdown
You have shown/claimed that this line is failing:if (version != JPEG_LIB_VERSION)From the stack trace where does the value of
versionpassed into this function emanate from?Or are you not saying this is the cause of the SEGV? If that comes from accessing
*cinfothat is a different issue. -
@Creaperdown
You have shown/claimed that this line is failing:if (version != JPEG_LIB_VERSION)From the stack trace where does the value of
versionpassed into this function emanate from?Or are you not saying this is the cause of the SEGV? If that comes from accessing
*cinfothat is a different issue.@JonB Sadly QtCreator does not show me a stack trace. I only get the calling functions, then question marks right to the function I shared above.
-
@JonB Sadly QtCreator does not show me a stack trace. I only get the calling functions, then question marks right to the function I shared above.
@Creaperdown
Ah, OK. That is not a Creator limitation, it's gdb and the (lack of) source code/debug info.If you get a SEGV rather than the
ERREXIT2(...)in your original post, what is, say, the next line after thatifstatement? Is*cinfoimplicated [oic,cinfois passed toERREXIT2] and/or isstructsizean expected size? -
@ChrisW67 Is there a way that I could test if that buffer contains valid data?
@Creaperdown Where does the data come from? How are you passing it to QImage::fromData()? Are there threads active in your program, or is all this happening in the main thread?
-
@Creaperdown Where does the data come from? How are you passing it to QImage::fromData()? Are there threads active in your program, or is all this happening in the main thread?
@ChrisW67 I am downloading the data from my server where I have previously uploaded it to. Right now I noticed that another part of my application, that has been working just fine before, fails because of the same error. I managed to find the
versionin the above snippet is80andJPEG_LIB_VERSIONis 90. -
@Creaperdown
Ah, OK. That is not a Creator limitation, it's gdb and the (lack of) source code/debug info.If you get a SEGV rather than the
ERREXIT2(...)in your original post, what is, say, the next line after thatifstatement? Is*cinfoimplicated [oic,cinfois passed toERREXIT2] and/or isstructsizean expected size?@JonB it steps into
ERREXIT2(). The next line would be:GLOBAL(void) jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize) { int i; /* Guard against version mismatches between library and caller. */ cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */ if (version != JPEG_LIB_VERSION) ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version); if (structsize != SIZEOF(struct jpeg_decompress_struct)) ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize); -
@Creaperdown
You have shown/claimed that this line is failing:if (version != JPEG_LIB_VERSION)From the stack trace where does the value of
versionpassed into this function emanate from?Or are you not saying this is the cause of the SEGV? If that comes from accessing
*cinfothat is a different issue.@JonB And now i get a stack trace

-
Ok, now I have done some system updates and jpegs work fine in debug mode, but running the application in release mode still causes the same crash.
-
I still didn't find a solution to this, does anyone have another idea?