[Swfdec] 6 commits - libswfdec-gtk/swfdec_gtk_widget.c libswfdec/jpeg libswfdec/swfdec_image.c

Benjamin Otte company at kemper.freedesktop.org
Wed Apr 18 06:51:43 PDT 2007


 libswfdec-gtk/swfdec_gtk_widget.c |    4 +-
 libswfdec/jpeg/jpeg.c             |   55 ++++++++++++++++++++++----------------
 libswfdec/jpeg/jpeg_rgb_decoder.c |    1 
 libswfdec/swfdec_image.c          |   46 +++++++------------------------
 4 files changed, 47 insertions(+), 59 deletions(-)

New commits:
diff-tree a171b4ba49fbd8fa8addb521184fc9b2cde60e50 (from aefaca2f3c3d192c5e662a127036a9ced0139c43)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Apr 18 14:22:40 2007 +0200

    now that the jpeg lib ignores SOI and EOI properly, there's no longer a need to do it here

diff --git a/libswfdec/swfdec_image.c b/libswfdec/swfdec_image.c
index 128506b..5a60681 100644
--- a/libswfdec/swfdec_image.c
+++ b/libswfdec/swfdec_image.c
@@ -140,47 +140,23 @@ swfdec_jpeg_decode_argb (unsigned char *
     unsigned char *data2, int length2,
     void *outdata, int *width, int *height)
 {
-  unsigned char *tmpdata;
-  int tmplength;
   gboolean ret;
 
-  while (length1 >= 2 && data1[0] == 0xff &&
-      (data1[1] == 0xd9 || data1[1] == 0xd8)) {
-    data1 += 2;
-    length1 -= 2;
-  }
-  while (length1 >= 2 && data1[length1-2] == 0xff &&
-      (data1[length1-1] == 0xd9 || data1[length1-1] == 0xd8)) {
-    length1 -= 2;
-  }
-
   if (data2) {
-    while (length2 >= 2 && data2[0] == 0xff &&
-        (data2[1] == 0xd9 || data2[1] == 0xd8)) {
-      data2 += 2;
-      length2 -= 2;
-    }
-    while (length2 >= 2 && data2[length2-2] == 0xff &&
-        (data2[length2-1] == 0xd9 || data2[length2-1] == 0xd8)) {
-      length2 -= 2;
-    }
-  } else {
-    length2 = 0;
-  }
-
-  tmplength = length1 + length2 + 4;
-  tmpdata = g_malloc (tmplength);
+    unsigned char *tmpdata;
+    int tmplength;
 
-  tmpdata[0] = 0xff;
-  tmpdata[1] = 0xd8;
-  memcpy (tmpdata + 2, data1, length1);
-  memcpy (tmpdata + 2 + length1, data2, length2);
-  tmpdata[2 + length1 + length2] = 0xff;
-  tmpdata[2 + length1 + length2 + 1] = 0xd9;
+    tmplength = length1 + length2;
+    tmpdata = g_malloc (tmplength);
 
-  ret = jpeg_decode_argb (tmpdata, tmplength, outdata, width, height);
+    memcpy (tmpdata, data1, length1);
+    memcpy (tmpdata + length1, data2, length2);
+    ret = jpeg_decode_argb (tmpdata, tmplength, outdata, width, height);
 
-  g_free(tmpdata);
+    g_free (tmpdata);
+  } else {
+    ret = jpeg_decode_argb (data1, length1, outdata, width, height);
+  }
 
   return ret;
 }
diff-tree aefaca2f3c3d192c5e662a127036a9ced0139c43 (from ece06f4cdeb5ce268939bd1869968f6b17c9ea0c)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Apr 18 14:22:08 2007 +0200

    add code to ignore SOI and EOI markers

diff --git a/libswfdec/jpeg/jpeg.c b/libswfdec/jpeg/jpeg.c
index b0de148..58dd755 100644
--- a/libswfdec/jpeg/jpeg.c
+++ b/libswfdec/jpeg/jpeg.c
@@ -543,6 +543,7 @@ jpeg_decoder_get_marker (JpegDecoder *de
   int a,b;
   JpegBits *bits = &dec->bits;
 
+again:
   if (jpeg_bits_available(bits) < 2) {
     return FALSE;
   }
@@ -557,6 +558,12 @@ jpeg_decoder_get_marker (JpegDecoder *de
     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;
 }
@@ -580,6 +587,7 @@ 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)) {
@@ -589,6 +597,7 @@ jpeg_decoder_decode (JpegDecoder *dec)
     jpeg_decoder_error(dec, "not a JPEG image");
     return FALSE;
   }
+#endif
 
   /* Interpret markers up to the start of frame */
   while (!dec->error) {
diff-tree ece06f4cdeb5ce268939bd1869968f6b17c9ea0c (from f5c204e01c3214748206d668bda81693091434e9)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Apr 18 13:46:26 2007 +0200

    fix memleak

diff --git a/libswfdec/jpeg/jpeg_rgb_decoder.c b/libswfdec/jpeg/jpeg_rgb_decoder.c
index 2949751..e1dba8a 100644
--- a/libswfdec/jpeg/jpeg_rgb_decoder.c
+++ b/libswfdec/jpeg/jpeg_rgb_decoder.c
@@ -62,6 +62,7 @@ int jpeg_decode_argb (uint8_t *data, int
 
   jpeg_decoder_get_image_size (dec, width, height);
   *image = (uint32_t *)jpeg_decoder_get_argb_image (dec);
+  jpeg_decoder_free (dec);
 
   return TRUE;
 }
diff-tree f5c204e01c3214748206d668bda81693091434e9 (from 34f141f73e3f5d263d9d089c95c79c5c1014f7ff)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Apr 18 13:46:10 2007 +0200

    change jpeg_decoder_error so the SWFDEC_ERROR prints the correct line number

diff --git a/libswfdec/jpeg/jpeg.c b/libswfdec/jpeg/jpeg.c
index 62aa499..b0de148 100644
--- a/libswfdec/jpeg/jpeg.c
+++ b/libswfdec/jpeg/jpeg.c
@@ -21,8 +21,6 @@
 extern uint8_t jpeg_standard_tables[];
 extern int jpeg_standard_tables_size;
 
-void jpeg_decoder_error(JpegDecoder *dec, char *fmt, ...);
-
 void jpeg_decoder_define_huffman_tables (JpegDecoder * dec);
 void jpeg_decoder_define_arithmetic_conditioning (JpegDecoder *dec);
 void jpeg_decoder_define_quantization_tables (JpegDecoder *dec);
@@ -41,6 +39,26 @@ static void jpeg_decoder_verify_header (
 static void jpeg_decoder_init_decoder (JpegDecoder *dec);
 
 
+static void
+jpeg_decoder_error(JpegDecoder *dec, char *fmt, ...)
+{
+  va_list varargs;
+
+  if (dec->error) return;
+
+  dec->error_message = malloc(250);
+  va_start (varargs, fmt);
+  vsnprintf(dec->error_message, 250 - 1, fmt, varargs);
+  dec->error_message[250 - 1] = 0;
+  va_end (varargs);
+
+  dec->error = TRUE;
+}
+
+#define jpeg_decoder_error(dec, ...) { \
+  SWFDEC_ERROR("decoder error: "__VA_ARGS__); \
+  jpeg_decoder_error (dec, __VA_ARGS__); \
+}
 
 static void
 jpeg_decoder_verify_header (JpegDecoder *dec)
@@ -519,23 +537,6 @@ jpeg_decoder_free (JpegDecoder * dec)
   free (dec);
 }
 
-void
-jpeg_decoder_error(JpegDecoder *dec, char *fmt, ...)
-{
-  va_list varargs;
-
-  if (dec->error) return;
-
-  dec->error_message = malloc(250);
-  va_start (varargs, fmt);
-  vsnprintf(dec->error_message, 250 - 1, fmt, varargs);
-  dec->error_message[250 - 1] = 0;
-  va_end (varargs);
-
-  SWFDEC_ERROR("decoder error: %s", dec->error_message);
-  dec->error = TRUE;
-}
-
 int
 jpeg_decoder_get_marker (JpegDecoder *dec, int *marker)
 {
diff-tree 34f141f73e3f5d263d9d089c95c79c5c1014f7ff (from e31c3c6bbd51cc4288915c6cc2a59dfabc761750)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Apr 18 13:43:30 2007 +0200

    fix security problem with overreading available data

diff --git a/libswfdec/jpeg/jpeg.c b/libswfdec/jpeg/jpeg.c
index 0c648c2..62aa499 100644
--- a/libswfdec/jpeg/jpeg.c
+++ b/libswfdec/jpeg/jpeg.c
@@ -381,6 +381,7 @@ jpeg_decoder_decode_entropy_segment (Jpe
   short block2[64];
   unsigned char *newptr;
   int len;
+  int maxlen;
   int j;
   int i;
   int go;
@@ -389,11 +390,11 @@ jpeg_decoder_decode_entropy_segment (Jpe
   int ret;
 
   len = 0;
+  maxlen = jpeg_bits_available (bits) - 1;
   j = 0;
-  while (1) {
-    if (bits->ptr[len] == 0xff && bits->ptr[len + 1] != 0x00) {
+  while (len < maxlen) {
+    if (bits->ptr[len] == 0xff && bits->ptr[len + 1] != 0x00)
       break;
-    }
     len++;
   }
   SWFDEC_DEBUG ("entropy length = %d", len);
diff-tree e31c3c6bbd51cc4288915c6cc2a59dfabc761750 (from 15ed4a69b4ffc265fe103ba79a0b60af7e42a9fa)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Apr 18 11:24:32 2007 +0200

    query mouse cursor when widget _is_ interactive

diff --git a/libswfdec-gtk/swfdec_gtk_widget.c b/libswfdec-gtk/swfdec_gtk_widget.c
index dcd39a0..ec0244e 100644
--- a/libswfdec-gtk/swfdec_gtk_widget.c
+++ b/libswfdec-gtk/swfdec_gtk_widget.c
@@ -323,9 +323,9 @@ swfdec_gtk_widget_update_cursor (SwfdecG
   if (window == NULL)
     return;
   if (priv->interactive)
-    swfcursor = SWFDEC_MOUSE_CURSOR_NORMAL;
-  else
     g_object_get (priv->player, "mouse-cursor", &swfcursor, NULL);
+  else
+    swfcursor = SWFDEC_MOUSE_CURSOR_NORMAL;
 
   switch (swfcursor) {
     case SWFDEC_MOUSE_CURSOR_NONE:


More information about the Swfdec mailing list