jpegdec: avoid crashing on invalid input without components
authorMark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
Mon, 4 Jul 2011 12:30:09 +0000 (14:30 +0200)
committerMark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
Mon, 4 Jul 2011 12:32:27 +0000 (14:32 +0200)
ext/jpeg/gstjpegdec.c

index 4d1be83f6a23b6147c1fd133d689d9735d66008a..23e8f23b8c4b67b1068f031391b8534031f80715 100644 (file)
@@ -1346,12 +1346,16 @@ again:
     GST_WARNING_OBJECT (dec, "reading the header failed, %d", hdr_ok);
   }
 
+  GST_LOG_OBJECT (dec, "num_components=%d", dec->cinfo.num_components);
+  GST_LOG_OBJECT (dec, "jpeg_color_space=%d", dec->cinfo.jpeg_color_space);
+
+  if (!dec->cinfo.num_components || !dec->cinfo.comp_info)
+    goto components_not_supported;
+
   r_h = dec->cinfo.comp_info[0].h_samp_factor;
   r_v = dec->cinfo.comp_info[0].v_samp_factor;
 
   GST_LOG_OBJECT (dec, "r_h = %d, r_v = %d", r_h, r_v);
-  GST_LOG_OBJECT (dec, "num_components=%d", dec->cinfo.num_components);
-  GST_LOG_OBJECT (dec, "jpeg_color_space=%d", dec->cinfo.jpeg_color_space);
 
   if (dec->cinfo.num_components > 3)
     goto components_not_supported;
@@ -1624,7 +1628,8 @@ drop_buffer:
 components_not_supported:
   {
     gst_jpeg_dec_set_error (dec, GST_FUNCTION, __LINE__,
-        "more components than supported: %d > 3", dec->cinfo.num_components);
+        "number of components not supported: %d (max 3)",
+        dec->cinfo.num_components);
     ret = GST_FLOW_ERROR;
     goto done;
   }