diff options
Diffstat (limited to 'libavcodec/bmv.c')
-rw-r--r-- | libavcodec/bmv.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/libavcodec/bmv.c b/libavcodec/bmv.c index a082d3c..715e6a3 100644 --- a/libavcodec/bmv.c +++ b/libavcodec/bmv.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/avassert.h" #include "libavutil/channel_layout.h" #include "avcodec.h" #include "bytestream.h" @@ -100,6 +101,8 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame, } if (!(val & 0xC)) { for (;;) { + if(shift>22) + return -1; if (!read_two_nibbles) { if (src < source || src >= source_end) return AVERROR_INVALIDDATA; @@ -133,6 +136,7 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame, } advance_mode = val & 1; len = (val >> 1) - 1; + av_assert0(len>0); mode += 1 + advance_mode; if (mode >= 4) mode -= 3; @@ -185,8 +189,6 @@ static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame, memset(dst, val, len); } break; - default: - break; } if (dst == dst_end) return 0; @@ -226,7 +228,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, return AVERROR_INVALIDDATA; } for (i = 0; i < 256; i++) - c->pal[i] = bytestream_get_be24(&c->stream); + c->pal[i] = 0xFFU << 24 | bytestream_get_be24(&c->stream); } if (type & BMV_SCROLL) { if (c->stream - pkt->data > pkt->size - 2) { @@ -280,6 +282,11 @@ static av_cold int decode_init(AVCodecContext *avctx) c->avctx = avctx; avctx->pix_fmt = AV_PIX_FMT_PAL8; + if (avctx->width != SCREEN_WIDE || avctx->height != SCREEN_HIGH) { + av_log(avctx, AV_LOG_ERROR, "Invalid dimension %dx%d\n", avctx->width, avctx->height); + return AVERROR_INVALIDDATA; + } + c->frame = c->frame_base + 640; return 0; |