diff options
author | Luca Barbato <lu_zero@gentoo.org> | 2013-06-07 16:16:46 +0200 |
---|---|---|
committer | Luca Barbato <lu_zero@gentoo.org> | 2013-06-16 15:54:15 +0200 |
commit | 6ddc1eb037042da814a62aa7f54517a897f0bdad (patch) | |
tree | 5766215eec500c98b9e9fc4fb258a9f37dcfc15f | |
parent | ded74ab5d1ccfef375090a0e828fa123c589083c (diff) | |
download | ffmpeg-6ddc1eb037042da814a62aa7f54517a897f0bdad.tar.gz |
4xm: validate the buffer size before parsing it
Reported-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
CC: libav-stable@libav.org
(cherry picked from commit de2e5777e225e75813daf2373c95e223651fd89a)
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
-rw-r--r-- | libavcodec/4xm.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/libavcodec/4xm.c b/libavcodec/4xm.c index dbf49177e6..493e2ad152 100644 --- a/libavcodec/4xm.c +++ b/libavcodec/4xm.c @@ -416,6 +416,8 @@ static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length) } if (f->version > 1) { + if (length < 20) + return AVERROR_INVALIDDATA; extra = 20; bitstream_size = AV_RL32(buf + 8); wordstream_size = AV_RL32(buf + 12); @@ -786,18 +788,29 @@ static int decode_frame(AVCodecContext *avctx, void *data, AVFrame *p, temp; int i, frame_4cc, frame_size; - frame_4cc = AV_RL32(buf); - if (buf_size != AV_RL32(buf + 4) + 8 || buf_size < 20) + if (buf_size < 20) + return AVERROR_INVALIDDATA; + + if (buf_size < AV_RL32(buf + 4) + 8) { av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d\n", buf_size, AV_RL32(buf + 4)); + return AVERROR_INVALIDDATA; + } + + frame_4cc = AV_RL32(buf); if (frame_4cc == AV_RL32("cfrm")) { int free_index = -1; + int id, whole_size; const int data_size = buf_size - 20; - const int id = AV_RL32(buf + 12); - const int whole_size = AV_RL32(buf + 16); CFrameBuffer *cfrm; + if (data_size < 0) + return AVERROR_INVALIDDATA; + + id = AV_RL32(buf + 12); + whole_size = AV_RL32(buf + 16); + for (i = 0; i < CFRAME_BUFFER_COUNT; i++) if (f->cfrm[i].id && f->cfrm[i].id < avctx->frame_number) av_log(f->avctx, AV_LOG_ERROR, "lost c frame %d\n", |