diff mbox series

[FFmpeg-devel] avcodec/faxcompr: Check for end of bitstream in decode_group3_1d_line() and decode_group3_2d_line()

Message ID 20210429151358.10952-1-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel] avcodec/faxcompr: Check for end of bitstream in decode_group3_1d_line() and decode_group3_2d_line()
Related show

Checks

Context Check Description
andriy/x86_make_warn warning New warnings during build
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Michael Niedermayer April 29, 2021, 3:13 p.m. UTC
Fixes: infinite loop
Fixes: 33674/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TIFF_fuzzer-4816457818046464

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

Comments

Andreas Rheinhardt April 29, 2021, 3:25 p.m. UTC | #1
Michael Niedermayer:
> Fixes: infinite loop
> Fixes: 33674/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TIFF_fuzzer-4816457818046464
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/faxcompr.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/libavcodec/faxcompr.c b/libavcodec/faxcompr.c
> index 7bf11d80ca..1fc4aca0b3 100644
> --- a/libavcodec/faxcompr.c
> +++ b/libavcodec/faxcompr.c
> @@ -209,6 +209,8 @@ static int decode_group3_1d_line(AVCodecContext *avctx, GetBitContext *gb,
>      unsigned int run = 0;
>      unsigned int t;
>      for (;;) {
> +        if (get_bits_left(gb) <= 0)
> +            return AVERROR_INVALIDDATA;
>          t    = get_vlc2(gb, ccitt_vlc[mode].table, 9, 2);
>          run += t;
>          if (t < 64) {
> @@ -254,6 +256,8 @@ static int decode_group3_2d_line(AVCodecContext *avctx, GetBitContext *gb,
>      unsigned int offs = 0, run = 0;
>  
>      while (offs < width) {
> +        if (get_bits_left(gb) <= 0)
> +            return AVERROR_INVALIDDATA;

This will give the typical statement-before-declaration warning.

>          int cmode = get_vlc2(gb, ccitt_group3_2d_vlc.table, 9, 1);
>          if (cmode == -1) {
>              av_log(avctx, AV_LOG_ERROR, "Incorrect mode VLC\n");
>
Michael Niedermayer May 4, 2021, 12:24 p.m. UTC | #2
On Thu, Apr 29, 2021 at 05:25:40PM +0200, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > Fixes: infinite loop
> > Fixes: 33674/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TIFF_fuzzer-4816457818046464
> > 
> > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/faxcompr.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/libavcodec/faxcompr.c b/libavcodec/faxcompr.c
> > index 7bf11d80ca..1fc4aca0b3 100644
> > --- a/libavcodec/faxcompr.c
> > +++ b/libavcodec/faxcompr.c
> > @@ -209,6 +209,8 @@ static int decode_group3_1d_line(AVCodecContext *avctx, GetBitContext *gb,
> >      unsigned int run = 0;
> >      unsigned int t;
> >      for (;;) {
> > +        if (get_bits_left(gb) <= 0)
> > +            return AVERROR_INVALIDDATA;
> >          t    = get_vlc2(gb, ccitt_vlc[mode].table, 9, 2);
> >          run += t;
> >          if (t < 64) {
> > @@ -254,6 +256,8 @@ static int decode_group3_2d_line(AVCodecContext *avctx, GetBitContext *gb,
> >      unsigned int offs = 0, run = 0;
> >  
> >      while (offs < width) {
> > +        if (get_bits_left(gb) <= 0)
> > +            return AVERROR_INVALIDDATA;
> 
> This will give the typical statement-before-declaration warning.

will commit without the warning

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/faxcompr.c b/libavcodec/faxcompr.c
index 7bf11d80ca..1fc4aca0b3 100644
--- a/libavcodec/faxcompr.c
+++ b/libavcodec/faxcompr.c
@@ -209,6 +209,8 @@  static int decode_group3_1d_line(AVCodecContext *avctx, GetBitContext *gb,
     unsigned int run = 0;
     unsigned int t;
     for (;;) {
+        if (get_bits_left(gb) <= 0)
+            return AVERROR_INVALIDDATA;
         t    = get_vlc2(gb, ccitt_vlc[mode].table, 9, 2);
         run += t;
         if (t < 64) {
@@ -254,6 +256,8 @@  static int decode_group3_2d_line(AVCodecContext *avctx, GetBitContext *gb,
     unsigned int offs = 0, run = 0;
 
     while (offs < width) {
+        if (get_bits_left(gb) <= 0)
+            return AVERROR_INVALIDDATA;
         int cmode = get_vlc2(gb, ccitt_group3_2d_vlc.table, 9, 1);
         if (cmode == -1) {
             av_log(avctx, AV_LOG_ERROR, "Incorrect mode VLC\n");