diff mbox

[FFmpeg-devel,1/2] avcodec/diracdec: Fix integer overflow with quant

Message ID 20180107221337.23431-1-michael@niedermayer.cc
State Accepted
Commit eaa93175895568ef6c2542b13104874907d9c4ef
Headers show

Commit Message

Michael Niedermayer Jan. 7, 2018, 10:13 p.m. UTC
Fixes: signed integer overflow: 2 + 2147483646 cannot be represented in type 'int'
Fixes: 4792/clusterfuzz-testcase-minimized-6322450775146496

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/diracdec.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Michael Niedermayer Jan. 8, 2018, 8:52 p.m. UTC | #1
On Sun, Jan 07, 2018 at 11:13:36PM +0100, Michael Niedermayer wrote:
> Fixes: signed integer overflow: 2 + 2147483646 cannot be represented in type 'int'
> Fixes: 4792/clusterfuzz-testcase-minimized-6322450775146496
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> 
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/diracdec.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)

will apply patchset

[...]
diff mbox

Patch

diff --git a/libavcodec/diracdec.c b/libavcodec/diracdec.c
index 7157357d59..530e1c6ffd 100644
--- a/libavcodec/diracdec.c
+++ b/libavcodec/diracdec.c
@@ -509,16 +509,16 @@  static inline void codeblock(DiracContext *s, SubBand *b,
     }
 
     if (s->codeblock_mode && !(s->old_delta_quant && blockcnt_one)) {
-        int quant = b->quant;
+        int quant;
         if (is_arith)
-            quant += dirac_get_arith_int(c, CTX_DELTA_Q_F, CTX_DELTA_Q_DATA);
+            quant = dirac_get_arith_int(c, CTX_DELTA_Q_F, CTX_DELTA_Q_DATA);
         else
-            quant += dirac_get_se_golomb(gb);
-        if (quant < 0) {
+            quant = dirac_get_se_golomb(gb);
+        if (quant > INT_MAX - b->quant || b->quant + quant < 0) {
             av_log(s->avctx, AV_LOG_ERROR, "Invalid quant\n");
             return;
         }
-        b->quant = quant;
+        b->quant += quant;
     }
 
     if (b->quant > (DIRAC_MAX_QUANT_INDEX - 1)) {