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

Marcel Wiesweg marcel.wiesweg at gmx.de
Wed Dec 27 21:31:09 GMT 2006


------- 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         
marcel.wiesweg gmx de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED



------- Additional Comments From marcel.wiesweg gmx de  2006-12-27 22:31 -------
SVN commit 617056 by mwiesweg:

In jpegutils, use proper libjpeg error handling, as it is done in the jpegloader.
Sometimes the mimetype detection may fail, and libjpeg would call exit()
from the default error handler.

BUG: 139197


 M  +70 -5     jpegutils.cpp  


--- trunk/extragear/graphics/digikam/libs/jpegutils/jpegutils.cpp #617055:617056
 @ -35,6 +35,7  @
 #include <sys/stat.h>
 #include <unistd.h>
 #include <utime.h>
+#include <setjmp.h>
 #include <jpeglib.h>
 }
 
 @ -59,6 +60,54  @
 namespace Digikam
 {
 
+// To manage Errors/Warnings handling provide by libjpeg
+
+//#define ENABLE_DEBUG_MESSAGES
+
+struct jpegutils_jpeg_error_mgr : public jpeg_error_mgr
+{
+    jmp_buf setjmp_buffer;
+};
+
+static void jpegutils_jpeg_error_exit(j_common_ptr cinfo);
+static void jpegutils_jpeg_emit_message(j_common_ptr cinfo, int msg_level);
+static void jpegutils_jpeg_output_message(j_common_ptr cinfo);
+
+static void jpegutils_jpeg_error_exit(j_common_ptr cinfo)
+{
+    jpegutils_jpeg_error_mgr* myerr = (jpegutils_jpeg_error_mgr*) cinfo->err;
+
+    char buffer[JMSG_LENGTH_MAX];
+    (*cinfo->err->format_message)(cinfo, buffer);
+
+#ifdef ENABLE_DEBUG_MESSAGES
+    DDebug() << k_funcinfo << buffer << endl;
+#endif
+
+    longjmp(myerr->setjmp_buffer, 1);
+}
+
+static void jpegutils_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
+    DDebug() << k_funcinfo << buffer << " (" << msg_level << ")" << endl;
+#endif
+}
+
+static void jpegutils_jpeg_output_message(j_common_ptr cinfo)
+{
+    char buffer[JMSG_LENGTH_MAX];
+    (*cinfo->err->format_message)(cinfo, buffer);
+
+#ifdef ENABLE_DEBUG_MESSAGES
+    DDebug() << k_funcinfo << buffer << endl;
+#endif
+}
+
 bool exifRotate(const QString& file, const QString& documentName)
 {
     QFileInfo fi(file);
 @ -142,17 +191,21  @
     
         struct jpeg_decompress_struct srcinfo;
         struct jpeg_compress_struct   dstinfo;
-        struct jpeg_error_mgr jsrcerr, jdsterr;
+        struct jpegutils_jpeg_error_mgr jsrcerr, jdsterr;
         jvirt_barray_ptr* src_coef_arrays;
         jvirt_barray_ptr* dst_coef_arrays;
     
         // 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     = jpegutils_jpeg_error_exit;
+        srcinfo.err->emit_message   = jpegutils_jpeg_emit_message;
+        srcinfo.err->output_message = jpegutils_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     = jpegutils_jpeg_error_exit;
+        dstinfo.err->emit_message   = jpegutils_jpeg_emit_message;
+        dstinfo.err->output_message = jpegutils_jpeg_output_message;
     
         FILE *input_file;
         FILE *output_file;
 @ -172,6 +225,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