Commit 96c04694 authored by Michael Niedermayer's avatar Michael Niedermayer

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/ffmpegReviewed-by: 's avatarPaul B Mahol <onemda@gmail.com>
Signed-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent 3197b009
...@@ -211,6 +211,7 @@ static const AVCodecTag nsv_codec_audio_tags[] = { ...@@ -211,6 +211,7 @@ static const AVCodecTag nsv_codec_audio_tags[] = {
//static int nsv_load_index(AVFormatContext *s); //static int nsv_load_index(AVFormatContext *s);
static int nsv_read_chunk(AVFormatContext *s, int fill_header); static int nsv_read_chunk(AVFormatContext *s, int fill_header);
static int nsv_read_close(AVFormatContext *s);
/* try to find something we recognize, and set the state accordingly */ /* try to find something we recognize, and set the state accordingly */
static int nsv_resync(AVFormatContext *s) static int nsv_resync(AVFormatContext *s)
...@@ -492,25 +493,32 @@ static int nsv_read_header(AVFormatContext *s) ...@@ -492,25 +493,32 @@ static int nsv_read_header(AVFormatContext *s)
nsv->ahead[0].data = nsv->ahead[1].data = NULL; nsv->ahead[0].data = nsv->ahead[1].data = NULL;
for (i = 0; i < NSV_MAX_RESYNC_TRIES; i++) { for (i = 0; i < NSV_MAX_RESYNC_TRIES; i++) {
if (nsv_resync(s) < 0) err = nsv_resync(s);
return -1; if (err < 0)
goto fail;
if (nsv->state == NSV_FOUND_NSVF) { if (nsv->state == NSV_FOUND_NSVF) {
err = nsv_parse_NSVf_header(s); err = nsv_parse_NSVf_header(s);
if (err < 0) if (err < 0)
return err; goto fail;
} }
/* we need the first NSVs also... */ /* we need the first NSVs also... */
if (nsv->state == NSV_FOUND_NSVS) { if (nsv->state == NSV_FOUND_NSVS) {
err = nsv_parse_NSVs_header(s); err = nsv_parse_NSVs_header(s);
if (err < 0) if (err < 0)
return err; goto fail;
break; /* we just want the first one */ break; /* we just want the first one */
} }
} }
if (s->nb_streams < 1) /* no luck so far */ if (s->nb_streams < 1) { /* no luck so far */
return -1; err = AVERROR_INVALIDDATA;
goto fail;
}
/* now read the first chunk, so we can attempt to decode more info */ /* now read the first chunk, so we can attempt to decode more info */
err = nsv_read_chunk(s, 1); err = nsv_read_chunk(s, 1);
fail:
if (err < 0)
nsv_read_close(s);
av_log(s, AV_LOG_TRACE, "parsed header\n"); av_log(s, AV_LOG_TRACE, "parsed header\n");
return err; return err;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment