From: Michael Niedermayer <[email protected]>

Prevent integer overflows.

Signed-off-by: Luca Barbato <[email protected]>
---
 libavcodec/jpeg2kdec.c |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/libavcodec/jpeg2kdec.c b/libavcodec/jpeg2kdec.c
index 3ef864b..84eb484 100644
--- a/libavcodec/jpeg2kdec.c
+++ b/libavcodec/jpeg2kdec.c
@@ -652,10 +652,16 @@ static int jpeg2k_decode_packet(Jpeg2KDecoderContext *s,
             else if (incl < 0)
                 return incl;
 
-            if (!cblk->npasses)
-                cblk->nonzerobits = expn[bandno] + numgbits - 1 -
-                                    tag_tree_decode(s, prec->zerobits + cblkno,
-                                                    100);
+            if (!cblk->npasses) {
+                int v = expn[bandno] + numgbits - 1 -
+                        tag_tree_decode(s, prec->zerobits + cblkno, 100);
+                if (v < 0) {
+                    av_log(s->avctx, AV_LOG_ERROR,
+                           "nonzerobits %d invalid\n", v);
+                    return AVERROR_INVALIDDATA;
+                }
+                cblk->nonzerobits = v;
+            }
             if ((newpasses = getnpasses(s)) < 0)
                 return newpasses;
             if ((llen = getlblockinc(s)) < 0)
-- 
1.7.9.5

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to