diff mbox series

[FFmpeg-devel,1/2] avformat/wtvdec: Check for EOF before potentially reseting the eof state

Message ID 20201212113844.21201-1-michael@niedermayer.cc
State Accepted
Commit 69754e07f5133b20bc789c7dea5d05714f63bf7f
Headers show
Series [FFmpeg-devel,1/2] avformat/wtvdec: Check for EOF before potentially reseting the eof state | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Michael Niedermayer Dec. 12, 2020, 11:38 a.m. UTC
Fixes: infinite loop
Fixes: 28042/clusterfuzz-testcase-minimized-ffmpeg_dem_WTV_fuzzer-6311288967528448

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavformat/wtvdec.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Peter Ross Dec. 12, 2020, 8:12 p.m. UTC | #1
On Sat, Dec 12, 2020 at 12:38:43PM +0100, Michael Niedermayer wrote:
> Fixes: infinite loop
> Fixes: 28042/clusterfuzz-testcase-minimized-ffmpeg_dem_WTV_fuzzer-6311288967528448
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavformat/wtvdec.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/libavformat/wtvdec.c b/libavformat/wtvdec.c
> index 77908e6392..6c41e3c1a3 100644
> --- a/libavformat/wtvdec.c
> +++ b/libavformat/wtvdec.c
> @@ -953,6 +953,9 @@ static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_p
>          } else
>              av_log(s, AV_LOG_WARNING, "unsupported chunk:"FF_PRI_GUID"\n", FF_ARG_GUID(g));
>  
> +        if (avio_feof(pb))
> +            break;
> +
>          avio_skip(pb, WTV_PAD8(len) - consumed);
>      }
>      return AVERROR_EOF;
> -- 
> 2.17.1

curious how the infinte loop occurs here, as the while loop already tests avio_feof().

i suspect it is because the fuzzed case results in 'consumed > len', and therefore avio_skip is seeking backwards.

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
Michael Niedermayer Feb. 2, 2021, 10:56 a.m. UTC | #2
On Sun, Dec 13, 2020 at 07:12:29AM +1100, Peter Ross wrote:
> On Sat, Dec 12, 2020 at 12:38:43PM +0100, Michael Niedermayer wrote:
> > Fixes: infinite loop
> > Fixes: 28042/clusterfuzz-testcase-minimized-ffmpeg_dem_WTV_fuzzer-6311288967528448
> > 
> > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavformat/wtvdec.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/libavformat/wtvdec.c b/libavformat/wtvdec.c
> > index 77908e6392..6c41e3c1a3 100644
> > --- a/libavformat/wtvdec.c
> > +++ b/libavformat/wtvdec.c
> > @@ -953,6 +953,9 @@ static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_p
> >          } else
> >              av_log(s, AV_LOG_WARNING, "unsupported chunk:"FF_PRI_GUID"\n", FF_ARG_GUID(g));
> >  
> > +        if (avio_feof(pb))
> > +            break;
> > +
> >          avio_skip(pb, WTV_PAD8(len) - consumed);
> >      }
> >      return AVERROR_EOF;
> > -- 
> > 2.17.1
> 
> curious how the infinte loop occurs here, as the while loop already tests avio_feof().
> 
> i suspect it is because the fuzzed case results in 'consumed > len', and therefore avio_skip is seeking backwards.

yes, WTV_PAD8(len) is 88 and consumed is 124 in the testcase, the eof flag
is reset from the backward seek and so the other test doesnt trigger

thx

[...]
diff mbox series

Patch

diff --git a/libavformat/wtvdec.c b/libavformat/wtvdec.c
index 77908e6392..6c41e3c1a3 100644
--- a/libavformat/wtvdec.c
+++ b/libavformat/wtvdec.c
@@ -953,6 +953,9 @@  static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_p
         } else
             av_log(s, AV_LOG_WARNING, "unsupported chunk:"FF_PRI_GUID"\n", FF_ARG_GUID(g));
 
+        if (avio_feof(pb))
+            break;
+
         avio_skip(pb, WTV_PAD8(len) - consumed);
     }
     return AVERROR_EOF;