Commit eaa93175 authored by Michael Niedermayer's avatar Michael Niedermayer

avcodec/diracdec: Fix integer overflow with quant

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/ffmpegSigned-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent 1bcd7fef
...@@ -509,16 +509,16 @@ static inline void codeblock(DiracContext *s, SubBand *b, ...@@ -509,16 +509,16 @@ static inline void codeblock(DiracContext *s, SubBand *b,
} }
if (s->codeblock_mode && !(s->old_delta_quant && blockcnt_one)) { if (s->codeblock_mode && !(s->old_delta_quant && blockcnt_one)) {
int quant = b->quant; int quant;
if (is_arith) 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 else
quant += dirac_get_se_golomb(gb); quant = dirac_get_se_golomb(gb);
if (quant < 0) { if (quant > INT_MAX - b->quant || b->quant + quant < 0) {
av_log(s->avctx, AV_LOG_ERROR, "Invalid quant\n"); av_log(s->avctx, AV_LOG_ERROR, "Invalid quant\n");
return; return;
} }
b->quant = quant; b->quant += quant;
} }
if (b->quant > (DIRAC_MAX_QUANT_INDEX - 1)) { if (b->quant > (DIRAC_MAX_QUANT_INDEX - 1)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment