diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2014-01-06 17:12:15 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-01-21 16:42:32 +0100 |
commit | c9a8dfa5ae162d719f554915af7bf0c9f918c943 (patch) | |
tree | 71a1b439ae921169df4d9d709ba675b361175031 | |
parent | e6299a4cf9efc526da9c85522038a80c034b0ad3 (diff) | |
download | ffmpeg-c9a8dfa5ae162d719f554915af7bf0c9f918c943.tar.gz |
Merge commit '6892d145a0c80249bd61ee7dd31ec851c5076bcd'
* commit '6892d145a0c80249bd61ee7dd31ec851c5076bcd':
segafilm: fix leaks if reading the header fails
Conflicts:
libavformat/segafilm.c
See: ca5456db7fa62a81d8effa20fb7547c16dd1d796
Merged-by: Michael Niedermayer <michaelni@gmx.at>
(cherry picked from commit 2a58d5fc0e842ebc9a47523a8c3418580b40b4be)
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavformat/segafilm.c | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/libavformat/segafilm.c b/libavformat/segafilm.c index a56568c300..7d33189cf5 100644 --- a/libavformat/segafilm.c +++ b/libavformat/segafilm.c @@ -72,13 +72,22 @@ static int film_probe(AVProbeData *p) return AVPROBE_SCORE_MAX; } +static int film_read_close(AVFormatContext *s) +{ + FilmDemuxContext *film = s->priv_data; + + av_freep(&film->sample_table); + + return 0; +} + static int film_read_header(AVFormatContext *s) { FilmDemuxContext *film = s->priv_data; AVIOContext *pb = s->pb; AVStream *st; unsigned char scratch[256]; - int i; + int i, ret; unsigned int data_offset; unsigned int audio_frame_counter; @@ -203,14 +212,16 @@ static int film_read_header(AVFormatContext *s) for (i = 0; i < film->sample_count; i++) { /* load the next sample record and transfer it to an internal struct */ if (avio_read(pb, scratch, 16) != 16) { - av_freep(&film->sample_table); - return AVERROR(EIO); + ret = AVERROR(EIO); + goto fail; } film->sample_table[i].sample_offset = data_offset + AV_RB32(&scratch[0]); film->sample_table[i].sample_size = AV_RB32(&scratch[4]); - if (film->sample_table[i].sample_size > INT_MAX / 4) - return AVERROR_INVALIDDATA; + if (film->sample_table[i].sample_size > INT_MAX / 4) { + ret = AVERROR_INVALIDDATA; + goto fail; + } if (AV_RB32(&scratch[8]) == 0xFFFFFFFF) { film->sample_table[i].stream = film->audio_stream_index; film->sample_table[i].pts = audio_frame_counter; @@ -231,6 +242,9 @@ static int film_read_header(AVFormatContext *s) film->current_sample = 0; return 0; +fail: + film_read_close(s); + return ret; } static int film_read_packet(AVFormatContext *s, @@ -270,15 +284,6 @@ static int film_read_packet(AVFormatContext *s, return ret; } -static int film_read_close(AVFormatContext *s) -{ - FilmDemuxContext *film = s->priv_data; - - av_freep(&film->sample_table); - - return 0; -} - AVInputFormat ff_segafilm_demuxer = { .name = "film_cpk", .long_name = NULL_IF_CONFIG_SMALL("Sega FILM / CPK"), |