[Swfdec] libswfdec/jpeg

David Schleef ds at kemper.freedesktop.org
Mon Apr 23 19:50:53 PDT 2007


 libswfdec/jpeg/jpeg.c          |   35 +++++++++++++++++++++++------------
 libswfdec/jpeg/jpeg_internal.h |    1 +
 2 files changed, 24 insertions(+), 12 deletions(-)

New commits:
diff-tree 7f977c08a2fb481fb736609068fc9f10d428edab (from 3826e5d8efd94d0b67519e0837bcae24fee038c1)
Author: David Schleef <ds at gromit.(none)>
Date:   Mon Apr 23 19:31:01 2007 -0700

    Pull fixes from Cog.  Adds a strict field.  Refactors how EOI and SOI
    markers are ignored.  Fixes overrun bug triggered by scriptmask.swf.

diff --git a/libswfdec/jpeg/jpeg.c b/libswfdec/jpeg/jpeg.c
index b5d2471..4d2fd43 100644
--- a/libswfdec/jpeg/jpeg.c
+++ b/libswfdec/jpeg/jpeg.c
@@ -443,7 +443,7 @@ jpeg_decoder_decode_entropy_segment (Jpe
   y = dec->y;
   n = dec->restart_interval;
   if (n == 0) n = (1<<26); /* max number of blocks */
-  while (n-- > 0) {
+  while (go && n-- > 0) {
     for (i = 0; i < dec->scan_list_length; i++) {
       int dc_table_index;
       int ac_table_index;
@@ -546,7 +546,6 @@ jpeg_decoder_get_marker (JpegDecoder *de
   int a,b;
   JpegBits *bits = &dec->bits;
 
-again:
   if (jpeg_bits_available(bits) < 2) {
     return FALSE;
   }
@@ -561,12 +560,6 @@ again:
     b = jpeg_bits_get_u8 (bits);
   } while (b == 0xff && jpeg_bits_error(bits));
 
-  /* Flash seems to ignore SOI and EOI markers, so we do, too */
-  if (b == JPEG_MARKER_SOI ||
-      (b == JPEG_MARKER_EOI && jpeg_bits_available (bits) > 0)) {
-    goto again;
-  }
-
   *marker = b;
   return TRUE;
 }
@@ -590,17 +583,15 @@ jpeg_decoder_decode (JpegDecoder *dec)
 
   bits = &dec->bits;
 
-#if 0
   /* Note: The spec is ambiguous as to whether fill bytes can come
    * before the first marker.  We'll assume yes. */
   if (!jpeg_decoder_get_marker (dec, &marker)) {
     return FALSE;
   }
-  if (marker != JPEG_MARKER_SOI) {
+  if (dec->strict && marker != JPEG_MARKER_SOI) {
     jpeg_decoder_error(dec, "not a JPEG image");
     return FALSE;
   }
-#endif
 
   /* Interpret markers up to the start of frame */
   while (!dec->error) {
@@ -623,6 +614,16 @@ jpeg_decoder_decode (JpegDecoder *dec)
       jpeg_decoder_skip (dec);
     } else if (JPEG_MARKER_IS_START_OF_FRAME(marker)) {
       break;
+    } else if (marker == JPEG_MARKER_SOI) {
+      if (dec->strict) {
+        jpeg_decoder_error (dec, "unexpected SOI");
+        return FALSE;
+      }
+    } else if (marker == JPEG_MARKER_EOI) {
+      if (dec->strict) {
+        jpeg_decoder_error (dec, "unexpected EOI");
+        return FALSE;
+      }
     } else {
       jpeg_decoder_error(dec, "unexpected marker 0x%02x", marker);
       return FALSE;
@@ -665,8 +666,18 @@ jpeg_decoder_decode (JpegDecoder *dec)
       jpeg_decoder_decode_entropy_segment (dec);
     } else if (JPEG_MARKER_IS_RESET(marker)) {
       jpeg_decoder_decode_entropy_segment (dec);
+    } else if (marker == JPEG_MARKER_SOI) {
+      if (dec->strict) {
+        jpeg_decoder_error (dec, "unexpected SOI");
+        return FALSE;
+      }
     } else if (marker == JPEG_MARKER_EOI) {
-      break;
+      if (dec->strict) {
+        jpeg_decoder_error (dec, "unexpected EOI");
+        return FALSE;
+      } else {
+        break;
+      }
     } else {
       jpeg_decoder_error(dec, "unexpected marker 0x%02x", marker);
       return FALSE;
diff --git a/libswfdec/jpeg/jpeg_internal.h b/libswfdec/jpeg/jpeg_internal.h
index 3129374..35f694e 100644
--- a/libswfdec/jpeg/jpeg_internal.h
+++ b/libswfdec/jpeg/jpeg_internal.h
@@ -31,6 +31,7 @@ struct _JpegDecoder {
 	int n_components;
 	JpegBits bits;
         int error;
+        int strict;
         char *error_message;
 
         int sof_type;


More information about the Swfdec mailing list