OSDN Git Service

avcodec/smc: Check side data size before use
authorMichael Niedermayer <michael@niedermayer.cc>
Sun, 30 Oct 2016 14:12:12 +0000 (15:12 +0100)
committerMichael Niedermayer <michael@niedermayer.cc>
Mon, 31 Oct 2016 22:20:47 +0000 (23:20 +0100)
Fixes out of array read

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavcodec/smc.c

index 69d78ad..8952421 100644 (file)
@@ -431,7 +431,8 @@ static int smc_decode_frame(AVCodecContext *avctx,
     const uint8_t *buf = avpkt->data;
     int buf_size = avpkt->size;
     SmcContext *s = avctx->priv_data;
-    const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
+    int pal_size;
+    const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &pal_size);
     int ret;
 
     bytestream2_init(&s->gb, buf, buf_size);
@@ -439,9 +440,11 @@ static int smc_decode_frame(AVCodecContext *avctx,
     if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
         return ret;
 
-    if (pal) {
+    if (pal && pal_size == AVPALETTE_SIZE) {
         s->frame->palette_has_changed = 1;
         memcpy(s->pal, pal, AVPALETTE_SIZE);
+    } else if (pal) {
+        av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", pal_size);
     }
 
     smc_decode_stream(s);