diff mbox series

[FFmpeg-devel,7/7] avcodec/gemdec: Move all support checks before before image allocation

Message ID 20211205211907.30010-7-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel,1/7] avformat/vivo: Do not use the general expression evaluator for parsing a floating point value
Related show

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Michael Niedermayer Dec. 5, 2021, 9:19 p.m. UTC
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/gemdec.c | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)

Comments

Peter Ross Dec. 6, 2021, 7:44 a.m. UTC | #1
On Sun, Dec 05, 2021 at 10:19:07PM +0100, Michael Niedermayer wrote:
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/gemdec.c | 32 +++++++++++++++++++++-----------
>  1 file changed, 21 insertions(+), 11 deletions(-)
> 
> diff --git a/libavcodec/gemdec.c b/libavcodec/gemdec.c
> index eee21a50d4b..fd14b22390c 100644
> --- a/libavcodec/gemdec.c
> +++ b/libavcodec/gemdec.c
> @@ -157,10 +157,22 @@ static int gem_decode_frame(AVCodecContext *avctx,
>      if (header_size >= 11)
>          tag = bytestream2_peek_be32(&gb);
>  
> -    if (tag == AV_RB32("STTT") || tag == AV_RB32("TIMG") || tag == AV_RB32("XIMG") ||
> -        planes == 1 || planes == 2 || planes == 3 || planes == 4 ||
> -        planes == 8 || planes == 16 || planes == 24) {
> -    } else {
> +    if (tag == AV_RB32("STTT")) {
> +        if (planes != 4) {
> +            avpriv_request_sample(avctx, "STTT planes=%d", planes);
> +            return AVERROR_PATCHWELCOME;
> +        }
> +    } else if (tag == AV_RB32("TIMG")) {
> +        if (planes != 15) {
> +            avpriv_request_sample(avctx, "TIMG planes=%d", planes);
> +            return AVERROR_PATCHWELCOME;
> +        }
> +    } else if (tag == AV_RB32("XIMG")) {
> +        if (planes != 1 && planes != 2 && planes != 4 && planes != 8 && planes != 16 && planes != 24 && planes != 32) {
> +            avpriv_request_sample(avctx, "XIMG planes=%d", planes);
> +            return AVERROR_PATCHWELCOME;
> +        }
> +    } else if (planes != 1 && planes != 2 && planes != 3 && planes != 4 && planes != 8 && planes != 16 && planes != 24) {
>          avpriv_request_sample(avctx, "planes=%d", planes);
>          return AVERROR_PATCHWELCOME;
>      }
> @@ -184,14 +196,12 @@ static int gem_decode_frame(AVCodecContext *avctx,
>                  palette[i] = 0xFF000000 | r << 16 | g << 8 | b;
>              }
>          } else {
> -            avpriv_request_sample(avctx, "STTT planes=%d", planes);
> -            return AVERROR_PATCHWELCOME;
> +            av_assert0(0);
>          }
>      } else if (tag == AV_RB32("TIMG")) {
>          bytestream2_skip(&gb, 4);
>          if (planes != 15) {
> -            avpriv_request_sample(avctx, "TIMG planes=%d", planes);
> -            return AVERROR_PATCHWELCOME;
> +            av_assert0(0);
>          }
>      } else if (tag == AV_RB32("XIMG")) {
>          bytestream2_skip(&gb, 6);
> @@ -215,8 +225,7 @@ static int gem_decode_frame(AVCodecContext *avctx,
>              row_width = avctx->width * pixel_size;
>              put_lines = put_lines_bytes;
>          } else {
> -            avpriv_request_sample(avctx, "XIMG planes=%d", planes);
> -            return AVERROR_PATCHWELCOME;
> +            av_assert0(0);
>          }
>      } else if (planes == 1) {
>          palette[0] = 0xFFFFFFFF;
> @@ -244,7 +253,8 @@ static int gem_decode_frame(AVCodecContext *avctx,
>          planes = 1;
>          row_width = avctx->width * pixel_size;
>          put_lines = put_lines_bytes;
> -    }
> +    } else
> +        av_assert0(0);
>  
>      ret = av_reallocp_array(&avctx->priv_data, planes, row_width);
>      if (ret < 0)
> -- 
> 2.17.1

please apply

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
Michael Niedermayer Dec. 6, 2021, 1:21 p.m. UTC | #2
On Mon, Dec 06, 2021 at 06:44:00PM +1100, Peter Ross wrote:
> On Sun, Dec 05, 2021 at 10:19:07PM +0100, Michael Niedermayer wrote:
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/gemdec.c | 32 +++++++++++++++++++++-----------
> >  1 file changed, 21 insertions(+), 11 deletions(-)
> > 
> > diff --git a/libavcodec/gemdec.c b/libavcodec/gemdec.c
> > index eee21a50d4b..fd14b22390c 100644
> > --- a/libavcodec/gemdec.c
> > +++ b/libavcodec/gemdec.c
> > @@ -157,10 +157,22 @@ static int gem_decode_frame(AVCodecContext *avctx,
> >      if (header_size >= 11)
> >          tag = bytestream2_peek_be32(&gb);
> >  
> > -    if (tag == AV_RB32("STTT") || tag == AV_RB32("TIMG") || tag == AV_RB32("XIMG") ||
> > -        planes == 1 || planes == 2 || planes == 3 || planes == 4 ||
> > -        planes == 8 || planes == 16 || planes == 24) {
> > -    } else {
> > +    if (tag == AV_RB32("STTT")) {
> > +        if (planes != 4) {
> > +            avpriv_request_sample(avctx, "STTT planes=%d", planes);
> > +            return AVERROR_PATCHWELCOME;
> > +        }
> > +    } else if (tag == AV_RB32("TIMG")) {
> > +        if (planes != 15) {
> > +            avpriv_request_sample(avctx, "TIMG planes=%d", planes);
> > +            return AVERROR_PATCHWELCOME;
> > +        }
> > +    } else if (tag == AV_RB32("XIMG")) {
> > +        if (planes != 1 && planes != 2 && planes != 4 && planes != 8 && planes != 16 && planes != 24 && planes != 32) {
> > +            avpriv_request_sample(avctx, "XIMG planes=%d", planes);
> > +            return AVERROR_PATCHWELCOME;
> > +        }
> > +    } else if (planes != 1 && planes != 2 && planes != 3 && planes != 4 && planes != 8 && planes != 16 && planes != 24) {
> >          avpriv_request_sample(avctx, "planes=%d", planes);
> >          return AVERROR_PATCHWELCOME;
> >      }
> > @@ -184,14 +196,12 @@ static int gem_decode_frame(AVCodecContext *avctx,
> >                  palette[i] = 0xFF000000 | r << 16 | g << 8 | b;
> >              }
> >          } else {
> > -            avpriv_request_sample(avctx, "STTT planes=%d", planes);
> > -            return AVERROR_PATCHWELCOME;
> > +            av_assert0(0);
> >          }
> >      } else if (tag == AV_RB32("TIMG")) {
> >          bytestream2_skip(&gb, 4);
> >          if (planes != 15) {
> > -            avpriv_request_sample(avctx, "TIMG planes=%d", planes);
> > -            return AVERROR_PATCHWELCOME;
> > +            av_assert0(0);
> >          }
> >      } else if (tag == AV_RB32("XIMG")) {
> >          bytestream2_skip(&gb, 6);
> > @@ -215,8 +225,7 @@ static int gem_decode_frame(AVCodecContext *avctx,
> >              row_width = avctx->width * pixel_size;
> >              put_lines = put_lines_bytes;
> >          } else {
> > -            avpriv_request_sample(avctx, "XIMG planes=%d", planes);
> > -            return AVERROR_PATCHWELCOME;
> > +            av_assert0(0);
> >          }
> >      } else if (planes == 1) {
> >          palette[0] = 0xFFFFFFFF;
> > @@ -244,7 +253,8 @@ static int gem_decode_frame(AVCodecContext *avctx,
> >          planes = 1;
> >          row_width = avctx->width * pixel_size;
> >          put_lines = put_lines_bytes;
> > -    }
> > +    } else
> > +        av_assert0(0);
> >  
> >      ret = av_reallocp_array(&avctx->priv_data, planes, row_width);
> >      if (ret < 0)
> > -- 
> > 2.17.1
> 
> please apply

will apply

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/gemdec.c b/libavcodec/gemdec.c
index eee21a50d4b..fd14b22390c 100644
--- a/libavcodec/gemdec.c
+++ b/libavcodec/gemdec.c
@@ -157,10 +157,22 @@  static int gem_decode_frame(AVCodecContext *avctx,
     if (header_size >= 11)
         tag = bytestream2_peek_be32(&gb);
 
-    if (tag == AV_RB32("STTT") || tag == AV_RB32("TIMG") || tag == AV_RB32("XIMG") ||
-        planes == 1 || planes == 2 || planes == 3 || planes == 4 ||
-        planes == 8 || planes == 16 || planes == 24) {
-    } else {
+    if (tag == AV_RB32("STTT")) {
+        if (planes != 4) {
+            avpriv_request_sample(avctx, "STTT planes=%d", planes);
+            return AVERROR_PATCHWELCOME;
+        }
+    } else if (tag == AV_RB32("TIMG")) {
+        if (planes != 15) {
+            avpriv_request_sample(avctx, "TIMG planes=%d", planes);
+            return AVERROR_PATCHWELCOME;
+        }
+    } else if (tag == AV_RB32("XIMG")) {
+        if (planes != 1 && planes != 2 && planes != 4 && planes != 8 && planes != 16 && planes != 24 && planes != 32) {
+            avpriv_request_sample(avctx, "XIMG planes=%d", planes);
+            return AVERROR_PATCHWELCOME;
+        }
+    } else if (planes != 1 && planes != 2 && planes != 3 && planes != 4 && planes != 8 && planes != 16 && planes != 24) {
         avpriv_request_sample(avctx, "planes=%d", planes);
         return AVERROR_PATCHWELCOME;
     }
@@ -184,14 +196,12 @@  static int gem_decode_frame(AVCodecContext *avctx,
                 palette[i] = 0xFF000000 | r << 16 | g << 8 | b;
             }
         } else {
-            avpriv_request_sample(avctx, "STTT planes=%d", planes);
-            return AVERROR_PATCHWELCOME;
+            av_assert0(0);
         }
     } else if (tag == AV_RB32("TIMG")) {
         bytestream2_skip(&gb, 4);
         if (planes != 15) {
-            avpriv_request_sample(avctx, "TIMG planes=%d", planes);
-            return AVERROR_PATCHWELCOME;
+            av_assert0(0);
         }
     } else if (tag == AV_RB32("XIMG")) {
         bytestream2_skip(&gb, 6);
@@ -215,8 +225,7 @@  static int gem_decode_frame(AVCodecContext *avctx,
             row_width = avctx->width * pixel_size;
             put_lines = put_lines_bytes;
         } else {
-            avpriv_request_sample(avctx, "XIMG planes=%d", planes);
-            return AVERROR_PATCHWELCOME;
+            av_assert0(0);
         }
     } else if (planes == 1) {
         palette[0] = 0xFFFFFFFF;
@@ -244,7 +253,8 @@  static int gem_decode_frame(AVCodecContext *avctx,
         planes = 1;
         row_width = avctx->width * pixel_size;
         put_lines = put_lines_bytes;
-    }
+    } else
+        av_assert0(0);
 
     ret = av_reallocp_array(&avctx->priv_data, planes, row_width);
     if (ret < 0)