Message ID | 20200724230816.23460-1-michael@niedermayer.cc |
---|---|
State | Accepted |
Headers | show |
Series | [FFmpeg-devel] avformat/ape: Error out in case of EOF in the header | expand |
Context | Check | Description |
---|---|---|
andriy/default | pending | |
andriy/make | success | Make finished |
andriy/make_fate | success | Make fate finished |
Michael Niedermayer: > Fixes: OOM > Fixes: 24375/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-6216862443241472 > > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> > --- > libavformat/ape.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/libavformat/ape.c b/libavformat/ape.c > index 39a584aa98..e966063ad7 100644 > --- a/libavformat/ape.c > +++ b/libavformat/ape.c > @@ -253,7 +253,7 @@ static int ape_read_header(AVFormatContext * s) > avio_skip(pb, ape->wavheaderlength); > } > > - if(!ape->totalframes){ > + if(!ape->totalframes || pb->eof_reached){ > av_log(s, AV_LOG_ERROR, "No frames in the file!\n"); > return AVERROR(EINVAL); > } > @@ -298,8 +298,10 @@ static int ape_read_header(AVFormatContext * s) > for (i = 0; i < ape->totalframes && !pb->eof_reached; i++) > ape->bittable[i] = avio_r8(pb); > } > - if (pb->eof_reached) > - av_log(s, AV_LOG_WARNING, "File truncated\n"); > + if (pb->eof_reached) { > + av_log(s, AV_LOG_ERROR, "File truncated\n"); > + return AVERROR_INVALIDDATA; > + } The above will lead to a memleak as long as cleaning up on read_header failure is not automatic. Furthermore, it's the first of the checks that fixes the OOM scenario, not the second, isn't it? - Andreas PS: One could remove the allocations for seek- and bittable altogether; only ape_dumpinfo() needs to have the seektable, the bittable as well as the frames at the same time.
On Sat, Jul 25, 2020 at 06:10:44AM +0200, Andreas Rheinhardt wrote: > Michael Niedermayer: > > Fixes: OOM > > Fixes: 24375/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-6216862443241472 > > > > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg > > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> > > --- > > libavformat/ape.c | 8 +++++--- > > 1 file changed, 5 insertions(+), 3 deletions(-) > > > > diff --git a/libavformat/ape.c b/libavformat/ape.c > > index 39a584aa98..e966063ad7 100644 > > --- a/libavformat/ape.c > > +++ b/libavformat/ape.c > > @@ -253,7 +253,7 @@ static int ape_read_header(AVFormatContext * s) > > avio_skip(pb, ape->wavheaderlength); > > } > > > > - if(!ape->totalframes){ > > + if(!ape->totalframes || pb->eof_reached){ > > av_log(s, AV_LOG_ERROR, "No frames in the file!\n"); > > return AVERROR(EINVAL); > > } > > @@ -298,8 +298,10 @@ static int ape_read_header(AVFormatContext * s) > > for (i = 0; i < ape->totalframes && !pb->eof_reached; i++) > > ape->bittable[i] = avio_r8(pb); > > } > > - if (pb->eof_reached) > > - av_log(s, AV_LOG_WARNING, "File truncated\n"); > > + if (pb->eof_reached) { > > + av_log(s, AV_LOG_ERROR, "File truncated\n"); > > + return AVERROR_INVALIDDATA; > > + } > > The above will lead to a memleak as long as cleaning up on read_header > failure is not automatic. Furthermore, it's the first of the checks that > fixes the OOM scenario, not the second, isn't it? yes, will apply with the leak issue fixed > > - Andreas > > PS: One could remove the allocations for seek- and bittable altogether; > only ape_dumpinfo() needs to have the seektable, the bittable as well as > the frames at the same time. will post a patch doing that thx [...]
diff --git a/libavformat/ape.c b/libavformat/ape.c index 39a584aa98..e966063ad7 100644 --- a/libavformat/ape.c +++ b/libavformat/ape.c @@ -253,7 +253,7 @@ static int ape_read_header(AVFormatContext * s) avio_skip(pb, ape->wavheaderlength); } - if(!ape->totalframes){ + if(!ape->totalframes || pb->eof_reached){ av_log(s, AV_LOG_ERROR, "No frames in the file!\n"); return AVERROR(EINVAL); } @@ -298,8 +298,10 @@ static int ape_read_header(AVFormatContext * s) for (i = 0; i < ape->totalframes && !pb->eof_reached; i++) ape->bittable[i] = avio_r8(pb); } - if (pb->eof_reached) - av_log(s, AV_LOG_WARNING, "File truncated\n"); + if (pb->eof_reached) { + av_log(s, AV_LOG_ERROR, "File truncated\n"); + return AVERROR_INVALIDDATA; + } } ape->frames[0].pos = ape->firstframe;
Fixes: OOM Fixes: 24375/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-6216862443241472 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- libavformat/ape.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)