changeset 2619:c39756a516a5 libavcodec

buffer overflows
author michael
date Wed, 20 Apr 2005 09:52:04 +0000
parents fc91ca5b9066
children 08cce4785567
files indeo2.c
diffstat 1 files changed, 15 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/indeo2.c	Wed Apr 20 09:42:47 2005 +0000
+++ b/indeo2.c	Wed Apr 20 09:52:04 2005 +0000
@@ -53,7 +53,7 @@
 else if (value < 0) \
     value = 0; \
 
-static void ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst, int stride,
+static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst, int stride,
                              const uint8_t *table)
 {
     int i;
@@ -62,11 +62,16 @@
     int c;
     int t;
     
+    if(width&1)
+        return -1;
+
     /* first line contain absolute values, other lines contain deltas */
     while (out < width){
         c = ir2_get_code(&ctx->gb);
         if(c > 0x80) { /* we have a run */
             c -= 0x80;
+            if(out + c*2 > width)
+                return -1;
             for (i = 0; i < c * 2; i++)
                 dst[out++] = 0x80;
         } else { /* copy two values from table */
@@ -82,6 +87,8 @@
             c = ir2_get_code(&ctx->gb);
             if(c > 0x80) { /* we have a skip */
                 c -= 0x80;
+                if(out + c*2 > width)
+                    return -1;
                 for (i = 0; i < c * 2; i++) {
                     dst[out] = dst[out - stride];
                     out++;
@@ -99,16 +106,20 @@
         }
         dst += stride;
     }
+    return 0;
 }
 
-static void ir2_decode_plane_inter(Ir2Context *ctx, int width, int height, uint8_t *dst, int stride,
+static int ir2_decode_plane_inter(Ir2Context *ctx, int width, int height, uint8_t *dst, int stride,
                              const uint8_t *table)
 {
     int j;
     int out = 0;
     int c;
     int t;
-    
+
+    if(width&1)
+        return -1;
+
     for (j = 0; j < height; j++){
         out = 0;
         while (out < width){
@@ -129,6 +140,7 @@
         }
         dst += stride;
     }
+    return 0;
 }
 
 static int ir2_decode_frame(AVCodecContext *avctx,