[FFmpeg-devel] [PATCH] jpeg2000dec: make cblk->length(inc)/data use consistent

Nicolas BERTRAND nicoinattendu at gmail.com
Mon Jun 17 16:38:41 CEST 2013


Le 13/06/2013 09:39, Michael Niedermayer a écrit :
> Fixes Ticket2612
>
> Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> ---
>   libavcodec/jpeg2000dec.c |   12 +++---------
>   1 file changed, 3 insertions(+), 9 deletions(-)
>
> diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
> index da510c6..7625505 100644
> --- a/libavcodec/jpeg2000dec.c
> +++ b/libavcodec/jpeg2000dec.c
> @@ -653,17 +653,11 @@ static int jpeg2000_decode_packet(Jpeg2000DecoderContext *s,
>           for (cblkno = 0; cblkno < nb_code_blocks; cblkno++) {
>               Jpeg2000Cblk *cblk = prec->cblk + cblkno;
>               if (   bytestream2_get_bytes_left(&s->g) < cblk->lengthinc
> -                || sizeof(cblk->data) < cblk->lengthinc
> +                || sizeof(cblk->data) < cblk->length + cblk->lengthinc + 2
>               )
>                   return AVERROR(EINVAL);
> -            /* Code-block data can be empty. In that case initialize data
> -             * with 0xFFFF. */
> -            if (cblk->lengthinc > 0) {
> -                bytestream2_get_bufferu(&s->g, cblk->data, cblk->lengthinc);
> -            } else {
> -                cblk->data[0] = 0xFF;
> -                cblk->data[1] = 0xFF;
> -            }
> +
> +            bytestream2_get_bufferu(&s->g, cblk->data + cblk->length, cblk->lengthinc);
>               cblk->length   += cblk->lengthinc;
>               cblk->lengthinc = 0;
>           }
>
cblk->length is always 0,
case of empty codeblock is managed in decodde_cblk
so we can simplyfy with:
iff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index c7519c1..d61f5fe 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -637,18 +637,11 @@ static int 
jpeg2000_decode_packet(Jpeg2000DecoderContext *s,
          for (cblkno = 0; cblkno < nb_code_blocks; cblkno++) {
              Jpeg2000Cblk *cblk = prec->cblk + cblkno;
              if (   bytestream2_get_bytes_left(&s->g) < cblk->lengthinc
-                || sizeof(cblk->data) < cblk->lengthinc
+                || sizeof(cblk->data) < cblk->lengthinc + 2
              )
                  return AVERROR(EINVAL);
-            /* Code-block data can be empty. In that case initialize data
-             * with 0xFFFF. */
-            if (cblk->lengthinc > 0) {
-                bytestream2_get_bufferu(&s->g, cblk->data, 
cblk->lengthinc);
-            } else {
-                cblk->data[0] = 0xFF;
-                cblk->data[1] = 0xFF;
-            }
-            cblk->length   += cblk->lengthinc;
+            bytestream2_get_bufferu(&s->g, cblk->data, cblk->lengthinc);
+            cblk->length   = cblk->lengthinc;
              cblk->lengthinc = 0;
          }
      }


More information about the ffmpeg-devel mailing list