From: "Ronald S. Bultje" <rsbultje@gmail.com> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Cc: Eli Kobrin <kobrineli@ispras.ru> Subject: Re: [FFmpeg-devel] [PATCH] libswresample: Prevent out of bounds. Date: Wed, 2 Aug 2023 08:06:42 -0400 Message-ID: <CAEEMt2kJW8fHe302c_pVdcBFz8NP_qszx1ipZMCD+Q82X8sGhA@mail.gmail.com> (raw) In-Reply-To: <20230802113106.1138555-1-kobrineli@ispras.ru> Hi, On Wed, Aug 2, 2023 at 7:31 AM kobrineli <kobrineli@ispras.ru> wrote: > From: Eli Kobrin <kobrineli@ispras.ru> > > We've been fuzzing torchvision with [sydr-fuzz]( > https://github.com/ispras/oss-sydr-fuzz) > and found out of bounds error in ffmpeg project at audioconvert.c:51. > To prevent error we need to insert corresponding check and fix checks > for in and out fmt in swr_init. > > Signed-off-by: Eli Kobrin <kobrineli@ispras.ru> > --- > libswresample/audioconvert.c | 7 ++++++- > libswresample/swresample.c | 4 ++-- > 2 files changed, 8 insertions(+), 3 deletions(-) > > diff --git a/libswresample/audioconvert.c b/libswresample/audioconvert.c > index 1d75ba1495..701f4808a0 100644 > --- a/libswresample/audioconvert.c > +++ b/libswresample/audioconvert.c > @@ -148,7 +148,12 @@ AudioConvert *swri_audio_convert_alloc(enum > AVSampleFormat out_fmt, > int flags) > { > AudioConvert *ctx; > - conv_func_type *f = > fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt) + > AV_SAMPLE_FMT_NB*av_get_packed_sample_fmt(in_fmt)]; > + > + size_t idx = av_get_packed_sample_fmt(out_fmt) + AV_SAMPLE_FMT_NB * > av_get_packed_sample_fmt(in_fmt); > + if (idx >= AV_SAMPLE_FMT_NB * AV_SAMPLE_FMT_NB) > + return NULL; > + > + conv_func_type *f = fmt_pair_to_conv_functions[idx]; > This is not necessary anymore, please remove this portion. > diff --git a/libswresample/swresample.c b/libswresample/swresample.c > index 6dc329a9d0..b7cab36710 100644 > --- a/libswresample/swresample.c > +++ b/libswresample/swresample.c > @@ -196,11 +196,11 @@ av_cold int swr_init(struct SwrContext *s){ > > clear_context(s); > > - if(s-> in_sample_fmt >= AV_SAMPLE_FMT_NB){ > + if(s-> in_sample_fmt >= AV_SAMPLE_FMT_NB || s-> in_sample_fmt < 0){ > av_log(s, AV_LOG_ERROR, "Requested input sample format %d is > invalid\n", s->in_sample_fmt); > return AVERROR(EINVAL); > } > - if(s->out_sample_fmt >= AV_SAMPLE_FMT_NB){ > + if(s->out_sample_fmt >= AV_SAMPLE_FMT_NB || s->out_sample_fmt < 0){ > av_log(s, AV_LOG_ERROR, "Requested output sample format %d is > invalid\n", s->out_sample_fmt); > return AVERROR(EINVAL); > } > -- > 2.25.1 > You can simplify this to "if ((unsigned) s->in/out_sample_fmt >= AV_SAMPLE_FMT_NB)". Ronald _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2023-08-02 12:07 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-08-02 11:31 kobrineli 2023-08-02 12:06 ` Ronald S. Bultje [this message] 2023-08-02 12:14 ` kobrineli -- strict thread matches above, loose matches on Subject: below -- 2023-08-02 12:14 kobrineli 2023-08-02 15:37 ` Michael Niedermayer 2023-08-02 9:35 kobrineli 2023-08-02 10:51 ` Andreas Rheinhardt 2023-08-02 11:15 ` kobrineli 2023-08-02 11:19 ` kobrineli 2023-08-02 11:42 ` kobrineli
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=CAEEMt2kJW8fHe302c_pVdcBFz8NP_qszx1ipZMCD+Q82X8sGhA@mail.gmail.com \ --to=rsbultje@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ --cc=kobrineli@ispras.ru \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git