Skip to content

Commit

Permalink
Jpeg handler: Detangle error reporting from the abort handling
Browse files Browse the repository at this point in the history
If libjpeg has detected a fatal error, wait until after the longjmp to
report the error using qCWarning(), as some compilers don't like that
happening before the stack has been restored.
Also avoids code duplication.

Fixes: QTBUG-100821
Pick-to: 6.3 6.2
Change-Id: I8d0e6e1bcc4f2a85dae06b3879453ee9077288c0
Reviewed-by: Qt CI Bot <[email protected]>
Reviewed-by: Volker Hilsheimer <[email protected]>
Reviewed-by: Heikki Halmet <[email protected]>
  • Loading branch information
aavit committed Mar 22, 2022
1 parent 5a41067 commit d0a2998
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/plugins/imageformats/jpeg/qjpeghandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ extern "C" {
static void my_error_exit (j_common_ptr cinfo)
{
my_error_mgr* myerr = (my_error_mgr*) cinfo->err;
char buffer[JMSG_LENGTH_MAX];
(*cinfo->err->format_message)(cinfo, buffer);
qCWarning(lcJpeg, "%s", buffer);
longjmp(myerr->setjmp_buffer, 1);
}

Expand Down Expand Up @@ -353,7 +350,7 @@ static bool read_jpeg_image(QImage *outImage,

// Allocate memory for the clipped QImage.
if (!ensureValidImage(outImage, info, clip.size()))
longjmp(err->setjmp_buffer, 1);
return false;

// Avoid memcpy() overhead if grayscale with no clipping.
bool quickGray = (info->output_components == 1 &&
Expand Down Expand Up @@ -429,8 +426,10 @@ static bool read_jpeg_image(QImage *outImage,
*outImage = outImage->copy(scaledClipRect);
return !outImage->isNull();
}
else
else {
my_output_message(j_common_ptr(info));
return false;
}
}

struct my_jpeg_destination_mgr : public jpeg_destination_mgr {
Expand Down Expand Up @@ -704,6 +703,7 @@ static bool do_write_jpeg_image(struct jpeg_compress_struct &cinfo,
jpeg_destroy_compress(&cinfo);
success = true;
} else {
my_output_message(j_common_ptr(&cinfo));
jpeg_destroy_compress(&cinfo);
success = false;
}
Expand Down Expand Up @@ -986,8 +986,8 @@ bool QJpegHandlerPrivate::readJpegHeader(QIODevice *device)
state = ReadHeader;
return true;
}
else
{
else {
my_output_message(j_common_ptr(&info));
return false;
}
}
Expand Down

0 comments on commit d0a2998

Please sign in to comment.