diff options
author | Michael Niedermayer <michael@niedermayer.cc> | 2020-03-18 20:20:44 +0100 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2020-04-23 21:29:01 +0200 |
commit | a31fc54c6c9b8e21ecb3b89f0cb1322d66826427 (patch) | |
tree | 3598437f136137183ef5c5a7b35b8138ec3ee93e | |
parent | c00a5fc71f144b5f70efcefb4910b8afd53c274a (diff) | |
download | ffmpeg-a31fc54c6c9b8e21ecb3b89f0cb1322d66826427.tar.gz |
avformat/nsvdec: Fix memleaks on errors while reading the header
Fixes: memleaks
Fixes: 21084/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5655975492321280
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 96c04694550999cc214cae8c4a16d2d7ac0958bc)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r-- | libavformat/nsvdec.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/libavformat/nsvdec.c b/libavformat/nsvdec.c index 9727aafcca..b427585eb4 100644 --- a/libavformat/nsvdec.c +++ b/libavformat/nsvdec.c @@ -212,6 +212,7 @@ static const AVCodecTag nsv_codec_audio_tags[] = { //static int nsv_load_index(AVFormatContext *s); static int nsv_read_chunk(AVFormatContext *s, int fill_header); +static int nsv_read_close(AVFormatContext *s); #define print_tag(str, tag, size) \ av_log(NULL, AV_LOG_TRACE, "%s: tag=%c%c%c%c\n", \ @@ -513,25 +514,32 @@ static int nsv_read_header(AVFormatContext *s) nsv->ahead[0].data = nsv->ahead[1].data = NULL; for (i = 0; i < NSV_MAX_RESYNC_TRIES; i++) { - if (nsv_resync(s) < 0) - return -1; + err = nsv_resync(s); + if (err < 0) + goto fail; if (nsv->state == NSV_FOUND_NSVF) { err = nsv_parse_NSVf_header(s); if (err < 0) - return err; + goto fail; } /* we need the first NSVs also... */ if (nsv->state == NSV_FOUND_NSVS) { err = nsv_parse_NSVs_header(s); if (err < 0) - return err; + goto fail; break; /* we just want the first one */ } } - if (s->nb_streams < 1) /* no luck so far */ - return -1; + if (s->nb_streams < 1) { /* no luck so far */ + err = AVERROR_INVALIDDATA; + goto fail; + } + /* now read the first chunk, so we can attempt to decode more info */ err = nsv_read_chunk(s, 1); +fail: + if (err < 0) + nsv_read_close(s); av_log(s, AV_LOG_TRACE, "parsed header\n"); return err; |