[Digikam-devel] [Bug 139197] crash during import of raw imagefiles (dng)

Marcel Wiesweg marcel.wiesweg at gmx.de
Wed Jan 3 16:27:22 GMT 2007


------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
         
http://bugs.kde.org/show_bug.cgi?id=139197         




------- Additional Comments From marcel.wiesweg gmx de  2007-01-03 17:27 -------
SVN commit 619526 by mwiesweg:

Port back fix for digikam bug 139197 to JPEGLossLess:
Use proper libjpeg error handling.
In case of an error, libjpeg would call exit() from the default error handler.

CCBUG: 139197


 M  +70 -5     jpegtransform.cpp  


--- trunk/extragear/libs/kipi-plugins/jpeglossless/jpegtransform.cpp #619525:619526
 @ -32,6 +32,7  @
 {
 #include <sys/types.h>
 #include <unistd.h>
+#include <setjmp.h>
 #include <jpeglib.h>
 }
 
 @ -66,6 +67,54  @
 Matrix Matrix::rotate90flipVertical   ( 0, -1, -1,  0);
 
 
+// To manage Errors/Warnings handling provide by libjpeg
+
+//#define ENABLE_DEBUG_MESSAGES
+
+struct jpegtransform_jpeg_error_mgr : public jpeg_error_mgr
+{
+    jmp_buf setjmp_buffer;
+};
+
+static void jpegtransform_jpeg_error_exit(j_common_ptr cinfo);
+static void jpegtransform_jpeg_emit_message(j_common_ptr cinfo, int msg_level);
+static void jpegtransform_jpeg_output_message(j_common_ptr cinfo);
+
+static void jpegtransform_jpeg_error_exit(j_common_ptr cinfo)
+{
+    jpegtransform_jpeg_error_mgr* myerr = (jpegtransform_jpeg_error_mgr*) cinfo->err;
+
+    char buffer[JMSG_LENGTH_MAX];
+    (*cinfo->err->format_message)(cinfo, buffer);
+
+#ifdef ENABLE_DEBUG_MESSAGES
+    kdDebug() << k_funcinfo << buffer << endl;
+#endif
+
+    longjmp(myerr->setjmp_buffer, 1);
+}
+
+static void jpegtransform_jpeg_emit_message(j_common_ptr cinfo, int msg_level)
+{
+    Q_UNUSED(msg_level)
+    char buffer[JMSG_LENGTH_MAX];
+    (*cinfo->err->format_message)(cinfo, buffer);
+
+#ifdef ENABLE_DEBUG_MESSAGES
+    kdDebug() << k_funcinfo << buffer << " (" << msg_level << ")" << endl;
+#endif
+}
+
+static void jpegtransform_jpeg_output_message(j_common_ptr cinfo)
+{
+    char buffer[JMSG_LENGTH_MAX];
+    (*cinfo->err->format_message)(cinfo, buffer);
+
+#ifdef ENABLE_DEBUG_MESSAGES
+    kdDebug() << k_funcinfo << buffer << endl;
+#endif
+}
+
 bool transformJPEG(const QString& src, const QString& destGiven,
                    Matrix &userAction, QString& err)
 {
 @ -80,7 +129,7  @
 
     struct jpeg_decompress_struct srcinfo;
     struct jpeg_compress_struct dstinfo;
-    struct jpeg_error_mgr jsrcerr, jdsterr;
+    struct jpegtransform_jpeg_error_mgr jsrcerr, jdsterr;
     jvirt_barray_ptr * src_coef_arrays;
     jvirt_barray_ptr * dst_coef_arrays;
 
 @ -88,12 +137,16  @
     JXFORM_CODE flip,rotate;
 
     // Initialize the JPEG decompression object with default error handling
-    srcinfo.err = jpeg_std_error(&jsrcerr);
-    jpeg_create_decompress(&srcinfo);
+    srcinfo.err                 = jpeg_std_error(&jsrcerr);
+    srcinfo.err->error_exit     = jpegtransform_jpeg_error_exit;
+    srcinfo.err->emit_message   = jpegtransform_jpeg_emit_message;
+    srcinfo.err->output_message = jpegtransform_jpeg_output_message;
 
     // Initialize the JPEG compression object with default error handling
-    dstinfo.err = jpeg_std_error(&jdsterr);
-    jpeg_create_compress(&dstinfo);
+    dstinfo.err                 = jpeg_std_error(&jdsterr);
+    dstinfo.err->error_exit     = jpegtransform_jpeg_error_exit;
+    dstinfo.err->emit_message   = jpegtransform_jpeg_emit_message;
+    dstinfo.err->output_message = jpegtransform_jpeg_output_message;
 
     FILE *input_file;
     FILE *output_file;
 @ -115,6 +168,18  @
         return false;
     }
 
+    if (setjmp(jsrcerr.setjmp_buffer) || setjmp(jdsterr.setjmp_buffer))
+    {
+        jpeg_destroy_decompress(&srcinfo);
+        jpeg_destroy_compress(&dstinfo);
+        fclose(input_file);
+        fclose(output_file);
+        return false;
+    }
+
+    jpeg_create_decompress(&srcinfo);
+    jpeg_create_compress(&dstinfo);
+
     jpeg_stdio_src(&srcinfo, input_file);
     jcopy_markers_setup(&srcinfo, copyoption);



More information about the Digikam-devel mailing list