[FFmpeg-devel,1/3] avcodec/dirac_vlc: Check res_bits after its modified by APPEND_RESIDUE()

Submitted by Michael Niedermayer on Sept. 8, 2017, 9:29 p.m.

Details

Message ID 20170908212913.20478-1-michael@niedermayer.cc
State New
Headers show

Commit Message

Michael Niedermayer Sept. 8, 2017, 9:29 p.m.
Fixes: runtime error: left shift of 1073741838 by 1 places cannot be represented in type 'int32_t' (aka 'int')
Fixes: 3279/clusterfuzz-testcase-minimized-4564805744590848

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/dirac_vlc.c | 4 ++++
 1 file changed, 4 insertions(+)

Patch hide | download patch | download mbox

diff --git a/libavcodec/dirac_vlc.c b/libavcodec/dirac_vlc.c
index bd37f31f46..a475d3b0bc 100644
--- a/libavcodec/dirac_vlc.c
+++ b/libavcodec/dirac_vlc.c
@@ -63,6 +63,8 @@  int ff_dirac_golomb_read_32bit(DiracGolombLUT *lut_ctx, const uint8_t *buf,
         if (res_bits && l->sign) {
             int32_t coeff = 1;
             APPEND_RESIDUE(res, l->preamble);
+            if (res_bits >= RSIZE_BITS)
+                res_bits = res = 0;
             for (i = 0; i < (res_bits >> 1) - 1; i++) {
                 coeff <<= 1;
                 coeff |= (res >> (RSIZE_BITS - 2*i - 2)) & 1;
@@ -105,6 +107,8 @@  int ff_dirac_golomb_read_16bit(DiracGolombLUT *lut_ctx, const uint8_t *buf,
         if (res_bits && l->sign) {
             int32_t coeff = 1;
             APPEND_RESIDUE(res, l->preamble);
+            if (res_bits >= RSIZE_BITS)
+                res_bits = res = 0;
             for (i = 0; i < (res_bits >> 1) - 1; i++) {
                 coeff <<= 1;
                 coeff |= (res >> (RSIZE_BITS - 2*i - 2)) & 1;