Fix #891: Application crashes while viewing CR3 thumbnails
authorColin Clark <colin.clark@cclark.uk>
Tue, 11 May 2021 13:26:43 +0000 (14:26 +0100)
committerColin Clark <colin.clark@cclark.uk>
Tue, 11 May 2021 13:26:43 +0000 (14:26 +0100)
https://github.com/BestImageViewer/geeqie/issues/891

Change the method of extracting jpegs from a .cr3 file when libraw is
not installed.

This is not a real solution. The code simply scans for the mdat marker
to find the start of the jpeg section.

src/image_load_cr3.c

index 73221d4..1c3c549 100644 (file)
@@ -265,31 +265,45 @@ static gboolean image_loader_cr3_load (gpointer loader, const guchar *buf, gsize
 /** @FIXME Just start search at where full size jpeg should be,
  * / then search through the file looking for a jpeg end-marker
  */
-       guint64 align_buf;
        gboolean found = FALSE;
        gint i;
+       gint n;
 
-       memcpy(&align_buf, &buf[0xf2], sizeof(guint64));
-       buf = buf + GUINT64_FROM_BE(align_buf) + 0x10;
-
-       if (memcmp(&buf[0], "\xFF\xD8", 2) == 0)
+       n = 0;
+       while (n < count - 4 && !found)
                {
-               i = 0;
-               while (!found )
+               if (memcmp(&buf[n], "mdat", 4) == 0)
                        {
-                       if (memcmp(&buf[ i], "\xFF\xD9", 2) == 0)
+                       if (memcmp(&buf[n + 12], "\xFF\xD8", 2) == 0)
+                               {
+                               i = 0;
+                               while (!found )
+                                       {
+                                       if (memcmp(&buf[n + 12 + i], "\xFF\xD9", 2) == 0)
+                                               {
+                                               found = TRUE;
+                                               }
+                                       i++;
+                                       }
+                               }
+                       else
                                {
-                               found = TRUE;
+                               break;
                                }
-                       i = i + 1;
+                       }
+               else
+                       {
+                       n++;
                        }
                }
-       else
+
+       if (!found)
                {
                return FALSE;
                }
 
        count = i;
+       buf = (unsigned char *)buf + n + 12;
 
        lj->stereo = FALSE;