avcodec/cdgraphics: check buffer size before use
authorMichael Niedermayer <michaelni@gmx.at>
Tue, 7 May 2013 19:04:33 +0000 (21:04 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Mon, 13 May 2013 23:30:16 +0000 (01:30 +0200)
Fixes out of array accesses

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
(cherry picked from commit ad002e1a13a8df934bd6cb2c84175a4780ab8942)

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavcodec/cdgraphics.c

index 8638dca..72e569f 100644 (file)
@@ -295,7 +295,9 @@ static int cdg_decode_frame(AVCodecContext *avctx,
     inst    = bytestream_get_byte(&buf);
     inst    &= CDG_MASK;
     buf += 2;  /// skipping 2 unneeded bytes
-    bytestream_get_buffer(&buf, cdg_data, buf_size - CDG_HEADER_SIZE);
+
+    if (buf_size > CDG_HEADER_SIZE)
+        bytestream_get_buffer(&buf, cdg_data, buf_size - CDG_HEADER_SIZE);
 
     if ((command & CDG_MASK) == CDG_COMMAND) {
         switch (inst) {