diff libmpeg2/slice.c @ 27572:da2271c341ee

Update internal libmpeg2 copy to version 0.5.1.
author diego
date Sat, 13 Sep 2008 17:31:45 +0000
parents fd18fa10de53
children e83eef58b30a
line wrap: on
line diff
--- a/libmpeg2/slice.c	Sat Sep 13 17:06:42 2008 +0000
+++ b/libmpeg2/slice.c	Sat Sep 13 17:31:45 2008 +0000
@@ -450,7 +450,7 @@
 	break;	/* illegal, check needed to avoid buffer overflow */
     }
     dest[63] ^= mismatch & 16;
-    DUMPBITS (bit_buf, bits, 2);	/* dump end of block code */
+    DUMPBITS (bit_buf, bits, tab->len);	/* dump end of block code */
     decoder->bitstream_buf = bit_buf;
     decoder->bitstream_bits = bits;
     decoder->bitstream_ptr = bit_ptr;
@@ -508,7 +508,7 @@
 	    } else {
 
 		/* end of block. I commented out this code because if we */
-		/* dont exit here we will still exit at the later test :) */
+		/* do not exit here we will still exit at the later test :) */
 
 		/* if (i >= 128) break;	*/	/* end of block */
 
@@ -560,7 +560,7 @@
 	break;	/* illegal, check needed to avoid buffer overflow */
     }
     dest[63] ^= mismatch & 16;
-    DUMPBITS (bit_buf, bits, 4);	/* dump end of block code */
+    DUMPBITS (bit_buf, bits, tab->len);	/* dump end of block code */
     decoder->bitstream_buf = bit_buf;
     decoder->bitstream_bits = bits;
     decoder->bitstream_ptr = bit_ptr;
@@ -681,7 +681,7 @@
 	break;	/* illegal, check needed to avoid buffer overflow */
     }
     dest[63] ^= mismatch & 16;
-    DUMPBITS (bit_buf, bits, 2);	/* dump end of block code */
+    DUMPBITS (bit_buf, bits, tab->len);	/* dump end of block code */
     decoder->bitstream_buf = bit_buf;
     decoder->bitstream_bits = bits;
     decoder->bitstream_ptr = bit_ptr;
@@ -799,7 +799,7 @@
 	}
 	break;	/* illegal, check needed to avoid buffer overflow */
     }
-    DUMPBITS (bit_buf, bits, 2);	/* dump end of block code */
+    DUMPBITS (bit_buf, bits, tab->len);	/* dump end of block code */
     decoder->bitstream_buf = bit_buf;
     decoder->bitstream_bits = bits;
     decoder->bitstream_ptr = bit_ptr;
@@ -926,7 +926,7 @@
 	}
 	break;	/* illegal, check needed to avoid buffer overflow */
     }
-    DUMPBITS (bit_buf, bits, 2);	/* dump end of block code */
+    DUMPBITS (bit_buf, bits, tab->len);	/* dump end of block code */
     decoder->bitstream_buf = bit_buf;
     decoder->bitstream_bits = bits;
     decoder->bitstream_ptr = bit_ptr;
@@ -1569,18 +1569,24 @@
 
 #define NEXT_MACROBLOCK							\
 do {									\
-    if(decoder->quant_store) {                                          \
-       if (decoder->picture_structure == TOP_FIELD)                     \
-        decoder->quant_store[2*decoder->quant_stride*(decoder->v_offset>>4) \
-                    +(decoder->offset>>4)] = decoder->quantizer_scale;  \
-       else if (decoder->picture_structure == BOTTOM_FIELD)             \
-        decoder->quant_store[2*decoder->quant_stride*(decoder->v_offset>>4) \
-	            + decoder->quant_stride                             \
-                    +(decoder->offset>>4)] = decoder->quantizer_scale;  \
-       else                                                             \
-        decoder->quant_store[decoder->quant_stride*(decoder->v_offset>>4) \
-                    +(decoder->offset>>4)] = decoder->quantizer_scale;  \
-    }                                                                   \
+    if(decoder->quant_store) {						\
+	if (decoder->picture_structure == TOP_FIELD)			\
+	    decoder->quant_store[2 * decoder->quant_stride		\
+				 * (decoder->v_offset >> 4)		\
+				 + (decoder->offset >> 4)]		\
+		= decoder->quantizer_scale;				\
+	else if (decoder->picture_structure == BOTTOM_FIELD)		\
+	    decoder->quant_store[2 * decoder->quant_stride		\
+				 * (decoder->v_offset >> 4)		\
+				 + decoder->quant_stride		\
+				 + (decoder->offset >> 4)]		\
+		= decoder->quantizer_scale;				\
+	else								\
+	    decoder->quant_store[decoder->quant_stride			\
+				 * (decoder->v_offset >> 4)		\
+				 + (decoder->offset >> 4)]		\
+		= decoder->quantizer_scale;				\
+    }									\
     decoder->offset += 16;						\
     if (decoder->offset == decoder->width) {				\
 	do { /* just so we can use the break statement */		\
@@ -1604,6 +1610,10 @@
     }									\
 } while (0)
 
+/**
+ * Dummy motion decoding function, to avoid calling NULL in
+ * case of malformed streams.
+ */
 static void motion_dummy (mpeg2_decoder_t * const decoder,
                           motion_t * const motion,
                           mpeg2_mc_fct * const * const table)
@@ -1668,7 +1678,7 @@
     if (decoder->mpeg1) {
 	decoder->motion_parser[0] = motion_zero_420;
         decoder->motion_parser[MC_FIELD] = motion_dummy;
-	decoder->motion_parser[MC_FRAME] = motion_mp1;
+ 	decoder->motion_parser[MC_FRAME] = motion_mp1;
         decoder->motion_parser[MC_DMV] = motion_dummy;
 	decoder->motion_parser[4] = motion_reuse_420;
     } else if (decoder->picture_structure == FRAME_PICTURE) {
@@ -1894,6 +1904,14 @@
 
 	    motion_parser_t * parser;
 
+	    if (   ((macroblock_modes >> MOTION_TYPE_SHIFT) < 0)
+                || ((macroblock_modes >> MOTION_TYPE_SHIFT) >=
+                    (int)(sizeof(decoder->motion_parser) 
+                          / sizeof(decoder->motion_parser[0])))
+	       ) {
+		break; // Illegal !
+	    }
+
 	    parser =
 		decoder->motion_parser[macroblock_modes >> MOTION_TYPE_SHIFT];
 	    MOTION_CALL (parser, macroblock_modes);