X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fgdv.c;h=2be1e2ea7fd1e9f7fa437573db2b9337f7971862;hb=e27466d7e59f0a485f3720f33cd9c54d69fff138;hp=183286b55f178f335fa9ff12e40bf97cc6db440e;hpb=06476249cd2332e30b66576633b2827adf3478dd;p=ffmpeg diff --git a/libavcodec/gdv.c b/libavcodec/gdv.c index 183286b55f1..2be1e2ea7fd 100644 --- a/libavcodec/gdv.c +++ b/libavcodec/gdv.c @@ -308,7 +308,7 @@ static int decompress_5(AVCodecContext *avctx, unsigned skip) int len; int b = bytestream2_get_byte(gb); if (b == 0) { - break; + return 0; } if (b != 0xFF) { len = b; @@ -323,6 +323,8 @@ static int decompress_5(AVCodecContext *avctx, unsigned skip) lz_copy(pb, g2, off, len); } } + if (bytestream2_get_bytes_left_p(pb) > 0) + return AVERROR_INVALIDDATA; return 0; } @@ -356,7 +358,8 @@ static int decompress_68(AVCodecContext *avctx, unsigned skip, unsigned use8) if (val != ((1 << lbits) - 1)) { break; } - assert(lbits < 16); + if (lbits >= 16) + return AVERROR_INVALIDDATA; } for (i = 0; i < len; i++) { bytestream2_put_byte(pb, bytestream2_get_byte(gb)); @@ -445,6 +448,9 @@ static int decompress_68(AVCodecContext *avctx, unsigned skip, unsigned use8) } } + if (bytestream2_get_bytes_left_p(pb) > 0) + return AVERROR_INVALIDDATA; + return 0; } @@ -475,6 +481,8 @@ static int gdv_decode_frame(AVCodecContext *avctx, void *data, if (pal && pal_size == AVPALETTE_SIZE) memcpy(gdv->pal, pal, AVPALETTE_SIZE); + if (compression < 2 && bytestream2_get_bytes_left(gb) < 256*3) + return AVERROR_INVALIDDATA; rescale(gdv, gdv->frame, avctx->width, avctx->height, !!(flags & 0x10), !!(flags & 0x20)); @@ -482,8 +490,6 @@ static int gdv_decode_frame(AVCodecContext *avctx, void *data, case 1: memset(gdv->frame + PREAMBLE_SIZE, 0, gdv->frame_size - PREAMBLE_SIZE); case 0: - if (bytestream2_get_bytes_left(gb) < 256*3) - return AVERROR_INVALIDDATA; for (i = 0; i < 256; i++) { unsigned r = bytestream2_get_byte(gb); unsigned g = bytestream2_get_byte(gb); @@ -545,7 +551,7 @@ static int gdv_decode_frame(AVCodecContext *avctx, void *data, *got_frame = 1; - return ret < 0 ? ret : avpkt->size; + return avpkt->size; } static av_cold int gdv_decode_close(AVCodecContext *avctx)