From d0a299869be83043d4fbf987747e6f5ea90b794c Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Thu, 24 Feb 2022 11:51:42 +0100 Subject: [PATCH] Jpeg handler: Detangle error reporting from the abort handling 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 Reviewed-by: Volker Hilsheimer Reviewed-by: Heikki Halmet --- src/plugins/imageformats/jpeg/qjpeghandler.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/plugins/imageformats/jpeg/qjpeghandler.cpp b/src/plugins/imageformats/jpeg/qjpeghandler.cpp index a17afc0f696..6d88438c47f 100644 --- a/src/plugins/imageformats/jpeg/qjpeghandler.cpp +++ b/src/plugins/imageformats/jpeg/qjpeghandler.cpp @@ -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); } @@ -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 && @@ -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 { @@ -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; } @@ -986,8 +986,8 @@ bool QJpegHandlerPrivate::readJpegHeader(QIODevice *device) state = ReadHeader; return true; } - else - { + else { + my_output_message(j_common_ptr(&info)); return false; } }