aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/tta.c
diff options
context:
space:
mode:
authorwm4 <nfxjfg@googlemail.com>2015-02-03 14:41:10 +0100
committerMichael Niedermayer <michaelni@gmx.at>2015-02-03 16:02:32 +0100
commit6a0cd529a35190d9374b0b26504e71857cd67b83 (patch)
tree2dfecbb709e0aa36c016d4c5901264bee028c8b9 /libavformat/tta.c
parent22504396fe24673843f8d07e3df254b667f504ef (diff)
downloadandroid_external_ffmpeg-6a0cd529a35190d9374b0b26504e71857cd67b83.tar.gz
android_external_ffmpeg-6a0cd529a35190d9374b0b26504e71857cd67b83.tar.bz2
android_external_ffmpeg-6a0cd529a35190d9374b0b26504e71857cd67b83.zip
avformat/tta: fix crash with corrupted files
av_add_index_entry() can fail, for example because the parameters are invalid, or because memory allocation fails. Check this; it can actually happen with corrupted files. The second hunk is just for robustness. Just in case functions like ff_reduce_index() remove entries. (Not sure if this can actually happen.) Fixes ticket #4294. Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/tta.c')
-rw-r--r--libavformat/tta.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/libavformat/tta.c b/libavformat/tta.c
index 7174fd5438..d3b3fb0471 100644
--- a/libavformat/tta.c
+++ b/libavformat/tta.c
@@ -118,8 +118,10 @@ static int tta_read_header(AVFormatContext *s)
ffio_init_checksum(s->pb, tta_check_crc, UINT32_MAX);
for (i = 0; i < c->totalframes; i++) {
uint32_t size = avio_rl32(s->pb);
- av_add_index_entry(st, framepos, i * c->frame_size, size, 0,
- AVINDEX_KEYFRAME);
+ int r;
+ if ((r = av_add_index_entry(st, framepos, i * c->frame_size, size, 0,
+ AVINDEX_KEYFRAME)) < 0)
+ return r;
framepos += size;
}
crc = ffio_get_checksum(s->pb) ^ UINT32_MAX;
@@ -153,6 +155,11 @@ static int tta_read_packet(AVFormatContext *s, AVPacket *pkt)
if (c->currentframe >= c->totalframes)
return AVERROR_EOF;
+ if (st->nb_index_entries < c->totalframes) {
+ av_log(s, AV_LOG_ERROR, "Index entry disappeared\n");
+ return AVERROR_INVALIDDATA;
+ }
+
size = st->index_entries[c->currentframe].size;
ret = av_get_packet(s->pb, pkt, size);