[FFmpeg-devel,3/4] avformat/subtitles: Check nb_subs in ff_subtitles_queue_finalize()

Submitted by Michael Niedermayer on Oct. 4, 2019, 5:59 p.m.

Details

Message ID 20191004175942.14310-3-michael@niedermayer.cc
State New
Headers show

Commit Message

Michael Niedermayer Oct. 4, 2019, 5:59 p.m.
Fixes: null pointer dereference
Fixes: 17828/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5645915116797952

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

Comments

Andreas Rheinhardt Oct. 6, 2019, 5:43 a.m.
Michael Niedermayer:
> Fixes: null pointer dereference
> Fixes: 17828/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5645915116797952
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavformat/subtitles.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c
> index 659c99d1cf..ded1b910c5 100644
> --- a/libavformat/subtitles.c
> +++ b/libavformat/subtitles.c
> @@ -194,9 +194,10 @@ void ff_subtitles_queue_finalize(void *log_ctx, FFDemuxSubtitlesQueue *q)
>  {
>      int i;
>  
> -    qsort(q->subs, q->nb_subs, sizeof(*q->subs),
> -          q->sort == SUB_SORT_TS_POS ? cmp_pkt_sub_ts_pos
> -                                     : cmp_pkt_sub_pos_ts);
> +    if (q->nb_subs)
> +        qsort(q->subs, q->nb_subs, sizeof(*q->subs),
> +              q->sort == SUB_SORT_TS_POS ? cmp_pkt_sub_ts_pos
> +                                         : cmp_pkt_sub_pos_ts);
>      for (i = 0; i < q->nb_subs; i++)
>          if (q->subs[i].duration < 0 && i < q->nb_subs - 1)
>              q->subs[i].duration = q->subs[i + 1].pts - q->subs[i].pts;
> 
Why not simply use
if (!q->nb_subs)
    return;
After all, neither the loop nor drop_dups() does anything if there are
no subs. And you should mention ticket #8147.

- Andreas
Michael Niedermayer Oct. 6, 2019, 11:07 a.m.
On Sun, Oct 06, 2019 at 05:43:00AM +0000, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > Fixes: null pointer dereference
> > Fixes: 17828/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5645915116797952
> > 
> > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavformat/subtitles.c | 7 ++++---
> >  1 file changed, 4 insertions(+), 3 deletions(-)
> > 
> > diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c
> > index 659c99d1cf..ded1b910c5 100644
> > --- a/libavformat/subtitles.c
> > +++ b/libavformat/subtitles.c
> > @@ -194,9 +194,10 @@ void ff_subtitles_queue_finalize(void *log_ctx, FFDemuxSubtitlesQueue *q)
> >  {
> >      int i;
> >  
> > -    qsort(q->subs, q->nb_subs, sizeof(*q->subs),
> > -          q->sort == SUB_SORT_TS_POS ? cmp_pkt_sub_ts_pos
> > -                                     : cmp_pkt_sub_pos_ts);
> > +    if (q->nb_subs)
> > +        qsort(q->subs, q->nb_subs, sizeof(*q->subs),
> > +              q->sort == SUB_SORT_TS_POS ? cmp_pkt_sub_ts_pos
> > +                                         : cmp_pkt_sub_pos_ts);
> >      for (i = 0; i < q->nb_subs; i++)
> >          if (q->subs[i].duration < 0 && i < q->nb_subs - 1)
> >              q->subs[i].duration = q->subs[i + 1].pts - q->subs[i].pts;
> > 
> Why not simply use
> if (!q->nb_subs)
>     return;
> After all, neither the loop nor drop_dups() does anything if there are
> no subs. And you should mention ticket #8147.

ok will push with these changes

thx

[...]

Patch hide | download patch | download mbox

diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c
index 659c99d1cf..ded1b910c5 100644
--- a/libavformat/subtitles.c
+++ b/libavformat/subtitles.c
@@ -194,9 +194,10 @@  void ff_subtitles_queue_finalize(void *log_ctx, FFDemuxSubtitlesQueue *q)
 {
     int i;
 
-    qsort(q->subs, q->nb_subs, sizeof(*q->subs),
-          q->sort == SUB_SORT_TS_POS ? cmp_pkt_sub_ts_pos
-                                     : cmp_pkt_sub_pos_ts);
+    if (q->nb_subs)
+        qsort(q->subs, q->nb_subs, sizeof(*q->subs),
+              q->sort == SUB_SORT_TS_POS ? cmp_pkt_sub_ts_pos
+                                         : cmp_pkt_sub_pos_ts);
     for (i = 0; i < q->nb_subs; i++)
         if (q->subs[i].duration < 0 && i < q->nb_subs - 1)
             q->subs[i].duration = q->subs[i + 1].pts - q->subs[i].pts;