diff options
author | Michael Niedermayer <michael@niedermayer.cc> | 2020-10-28 20:11:54 +0100 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2021-09-10 16:04:26 +0200 |
commit | 955b471fbe77bdab4f007c43c65e71c596e212b5 (patch) | |
tree | 448ce7a9179bfb0bf6435507d50a9984dd072409 | |
parent | f201ec88d0de5b8ccd6c13c5b6be5e5ed148c052 (diff) | |
download | ffmpeg-955b471fbe77bdab4f007c43c65e71c596e212b5.tar.gz |
avformat/vividas: improve extradata packing checks in track_header()
Fixes: out of array accesses
Fixes: 26622/clusterfuzz-testcase-minimized-ffmpeg_dem_VIVIDAS_fuzzer-6581200338288640
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 27a99e2c7d450fef15594671eef4465c8a166bd7)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r-- | libavformat/vividas.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/libavformat/vividas.c b/libavformat/vividas.c index 82f5fce4fd..1eca294933 100644 --- a/libavformat/vividas.c +++ b/libavformat/vividas.c @@ -28,6 +28,7 @@ * @sa http://wiki.multimedia.cx/index.php?title=Vividas_VIV */ +#include "libavutil/avassert.h" #include "libavutil/intreadwrite.h" #include "avio_internal.h" #include "avformat.h" @@ -374,7 +375,7 @@ static int track_header(VividasDemuxContext *viv, AVFormatContext *s, uint8_t * if (avio_tell(pb) < off) { int num_data; - int xd_size = 0; + int xd_size = 1; int data_len[256]; int offset = 1; uint8_t *p; @@ -389,11 +390,10 @@ static int track_header(VividasDemuxContext *viv, AVFormatContext *s, uint8_t * return AVERROR_INVALIDDATA; } data_len[j] = len; - xd_size += len; + xd_size += len + 1 + len/255; } - st->codecpar->extradata_size = 64 + xd_size + xd_size / 255; - if (ff_alloc_extradata(st->codecpar, st->codecpar->extradata_size)) { + if (ff_alloc_extradata(st->codecpar, xd_size)) { av_free(pb); return AVERROR(ENOMEM); } @@ -403,10 +403,7 @@ static int track_header(VividasDemuxContext *viv, AVFormatContext *s, uint8_t * for (j = 0; j < num_data - 1; j++) { unsigned delta = av_xiphlacing(&p[offset], data_len[j]); - if (delta > data_len[j]) { - av_free(pb); - return AVERROR_INVALIDDATA; - } + av_assert0(delta <= xd_size - offset); offset += delta; } @@ -417,6 +414,7 @@ static int track_header(VividasDemuxContext *viv, AVFormatContext *s, uint8_t * av_freep(&st->codecpar->extradata); break; } + av_assert0(data_len[j] <= xd_size - offset); offset += data_len[j]; } |