libavcodec/bink.c:1029: error: Integer Overflow L2
  ([1, +oo] - 4):unsigned32 by call to `bitstream_read`.

libavcodec/bink.c:1029:42: Call
1027.                 switch (blk) {
1028.                 case RUN_BLOCK:
1029.                     scan = bink_patterns[bitstream_read(bc, 4)];
                                               ^
1030.                     i = 0;
1031.                     do {

libavcodec/bitstream.h:183:1: Parameter `n`
  181. 
  182. /* Return n bits from the buffer. n has to be in the 0-32 range. */
  183. static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)
       ^
  184. {
  185.     if (!n)

libavcodec/bitstream.h:194:12: Call
  192.     }
  193. 
  194.     return get_val(bc, n);
                  ^
  195. }
  196. 

libavcodec/bitstream.h:130:1: <LHS trace>
128. }
129. 
130. static inline uint64_t get_val(BitstreamContext *bc, unsigned n)
     ^
131. {
132. #ifdef BITSTREAM_READER_LE

libavcodec/bitstream.h:130:1: Parameter `bc->bits_left`
    128. }
    129. 
    130. static inline uint64_t get_val(BitstreamContext *bc, unsigned n)
         ^
    131. {
    132. #ifdef BITSTREAM_READER_LE

libavcodec/bitstream.h:130:1: <RHS trace>
128. }
129. 
130. static inline uint64_t get_val(BitstreamContext *bc, unsigned n)
     ^
131. {
132. #ifdef BITSTREAM_READER_LE

libavcodec/bitstream.h:130:1: Parameter `n`
    128. }
    129. 
    130. static inline uint64_t get_val(BitstreamContext *bc, unsigned n)
         ^
    131. {
    132. #ifdef BITSTREAM_READER_LE

libavcodec/bitstream.h:139:5: Binary operation: ([1, +oo] - 4):unsigned32 by call to `bitstream_read` 
    137.     bc->bits <<= n;
    138. #endif
    139.     bc->bits_left -= n;
             ^
    140. 
    141.     return ret;

static inline uint64_t get_val(BitstreamContext *bc, unsigned n)
{
#ifdef BITSTREAM_READER_LE
    uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);
    bc->bits >>= n;
#else
    uint64_t ret = bc->bits >> (64 - n);
    bc->bits <<= n;
#endif
    bc->bits_left -= n;
    return ret;
}
['static int bink_decode_plane(BinkContext *c, AVFrame *frame, BitstreamContext *bc,\n                             int plane_idx, int is_chroma)\n{\n    int blk, ret;\n    int i, j, bx, by;\n    uint8_t *dst, *prev, *ref_start, *ref_end;\n    int v, col[2];\n    const uint8_t *scan;\n    LOCAL_ALIGNED_16(int16_t, block, [64]);\n    LOCAL_ALIGNED_16(uint8_t, ublock, [64]);\n    LOCAL_ALIGNED_16(int32_t, dctblock, [64]);\n    int coordmap[64];\n    const int stride = frame->linesize[plane_idx];\n    int bw = is_chroma ? (c->avctx->width  + 15) >> 4 : (c->avctx->width  + 7) >> 3;\n    int bh = is_chroma ? (c->avctx->height + 15) >> 4 : (c->avctx->height + 7) >> 3;\n    int width = c->avctx->width >> is_chroma;\n    init_lengths(c, FFMAX(width, 8), bw);\n    for (i = 0; i < BINK_NB_SRC; i++)\n        read_bundle(bc, c, i);\n    ref_start = c->last->data[plane_idx] ? c->last->data[plane_idx]\n                                         : frame->data[plane_idx];\n    ref_end   = ref_start\n                + (bw - 1 + c->last->linesize[plane_idx] * (bh - 1)) * 8;\n    for (i = 0; i < 64; i++)\n        coordmap[i] = (i & 7) + (i >> 3) * stride;\n    for (by = 0; by < bh; by++) {\n        if ((ret = read_block_types(c->avctx, bc, &c->bundle[BINK_SRC_BLOCK_TYPES])) < 0)\n            return ret;\n        if ((ret = read_block_types(c->avctx, bc, &c->bundle[BINK_SRC_SUB_BLOCK_TYPES])) < 0)\n            return ret;\n        if ((ret = read_colors(bc, &c->bundle[BINK_SRC_COLORS], c)) < 0)\n            return ret;\n        if ((ret = read_patterns(c->avctx, bc, &c->bundle[BINK_SRC_PATTERN])) < 0)\n            return ret;\n        if ((ret = read_motion_values(c->avctx, bc, &c->bundle[BINK_SRC_X_OFF])) < 0)\n            return ret;\n        if ((ret = read_motion_values(c->avctx, bc, &c->bundle[BINK_SRC_Y_OFF])) < 0)\n            return ret;\n        if ((ret = read_dcs(c->avctx, bc, &c->bundle[BINK_SRC_INTRA_DC], DC_START_BITS, 0)) < 0)\n            return ret;\n        if ((ret = read_dcs(c->avctx, bc, &c->bundle[BINK_SRC_INTER_DC], DC_START_BITS, 1)) < 0)\n            return ret;\n        if ((ret = read_runs(c->avctx, bc, &c->bundle[BINK_SRC_RUN])) < 0)\n            return ret;\n        if (by == bh)\n            break;\n        dst  = frame->data[plane_idx]  + 8*by*stride;\n        prev = (c->last->data[plane_idx] ? c->last->data[plane_idx]\n                                         : frame->data[plane_idx]) + 8*by*stride;\n        for (bx = 0; bx < bw; bx++, dst += 8, prev += 8) {\n            blk = get_value(c, BINK_SRC_BLOCK_TYPES);\n            if ((by & 1) && blk == SCALED_BLOCK) {\n                bx++;\n                dst  += 8;\n                prev += 8;\n                continue;\n            }\n            switch (blk) {\n            case SKIP_BLOCK:\n                c->hdsp.put_pixels_tab[1][0](dst, prev, stride, 8);\n                break;\n            case SCALED_BLOCK:\n                blk = get_value(c, BINK_SRC_SUB_BLOCK_TYPES);\n                switch (blk) {\n                case RUN_BLOCK:\n                    scan = bink_patterns[bitstream_read(bc, 4)];\n                    i = 0;\n                    do {\n                        int run = get_value(c, BINK_SRC_RUN) + 1;\n                        i += run;\n                        if (i > 64) {\n                            av_log(c->avctx, AV_LOG_ERROR, "Run went out of bounds\\n");\n                            return AVERROR_INVALIDDATA;\n                        }\n                        if (bitstream_read_bit(bc)) {\n                            v = get_value(c, BINK_SRC_COLORS);\n                            for (j = 0; j < run; j++)\n                                ublock[*scan++] = v;\n                        } else {\n                            for (j = 0; j < run; j++)\n                                ublock[*scan++] = get_value(c, BINK_SRC_COLORS);\n                        }\n                    } while (i < 63);\n                    if (i == 63)\n                        ublock[*scan++] = get_value(c, BINK_SRC_COLORS);\n                    break;\n                case INTRA_BLOCK:\n                    memset(dctblock, 0, sizeof(*dctblock) * 64);\n                    dctblock[0] = get_value(c, BINK_SRC_INTRA_DC);\n                    read_dct_coeffs(bc, dctblock, bink_scan, bink_intra_quant, -1);\n                    c->binkdsp.idct_put(ublock, 8, dctblock);\n                    break;\n                case FILL_BLOCK:\n                    v = get_value(c, BINK_SRC_COLORS);\n                    c->bdsp.fill_block_tab[0](dst, v, stride, 16);\n                    break;\n                case PATTERN_BLOCK:\n                    for (i = 0; i < 2; i++)\n                        col[i] = get_value(c, BINK_SRC_COLORS);\n                    for (j = 0; j < 8; j++) {\n                        v = get_value(c, BINK_SRC_PATTERN);\n                        for (i = 0; i < 8; i++, v >>= 1)\n                            ublock[i + j*8] = col[v & 1];\n                    }\n                    break;\n                case RAW_BLOCK:\n                    for (j = 0; j < 8; j++)\n                        for (i = 0; i < 8; i++)\n                            ublock[i + j*8] = get_value(c, BINK_SRC_COLORS);\n                    break;\n                default:\n                    av_log(c->avctx, AV_LOG_ERROR, "Incorrect 16x16 block type %d\\n", blk);\n                    return AVERROR_INVALIDDATA;\n                }\n                if (blk != FILL_BLOCK)\n                c->binkdsp.scale_block(ublock, dst, stride);\n                bx++;\n                dst  += 8;\n                prev += 8;\n                break;\n            case MOTION_BLOCK:\n                ret = bink_put_pixels(c, dst, prev, stride,\n                                      ref_start, ref_end);\n                if (ret < 0)\n                    return ret;\n                break;\n            case RUN_BLOCK:\n                scan = bink_patterns[bitstream_read(bc, 4)];\n                i = 0;\n                do {\n                    int run = get_value(c, BINK_SRC_RUN) + 1;\n                    i += run;\n                    if (i > 64) {\n                        av_log(c->avctx, AV_LOG_ERROR, "Run went out of bounds\\n");\n                        return AVERROR_INVALIDDATA;\n                    }\n                    if (bitstream_read_bit(bc)) {\n                        v = get_value(c, BINK_SRC_COLORS);\n                        for (j = 0; j < run; j++)\n                            dst[coordmap[*scan++]] = v;\n                    } else {\n                        for (j = 0; j < run; j++)\n                            dst[coordmap[*scan++]] = get_value(c, BINK_SRC_COLORS);\n                    }\n                } while (i < 63);\n                if (i == 63)\n                    dst[coordmap[*scan++]] = get_value(c, BINK_SRC_COLORS);\n                break;\n            case RESIDUE_BLOCK:\n                ret = bink_put_pixels(c, dst, prev, stride,\n                                      ref_start, ref_end);\n                if (ret < 0)\n                    return ret;\n                c->bdsp.clear_block(block);\n                v = bitstream_read(bc, 7);\n                read_residue(bc, block, v);\n                c->binkdsp.add_pixels8(dst, block, stride);\n                break;\n            case INTRA_BLOCK:\n                memset(dctblock, 0, sizeof(*dctblock) * 64);\n                dctblock[0] = get_value(c, BINK_SRC_INTRA_DC);\n                read_dct_coeffs(bc, dctblock, bink_scan, bink_intra_quant, -1);\n                c->binkdsp.idct_put(dst, stride, dctblock);\n                break;\n            case FILL_BLOCK:\n                v = get_value(c, BINK_SRC_COLORS);\n                c->bdsp.fill_block_tab[1](dst, v, stride, 8);\n                break;\n            case INTER_BLOCK:\n                ret = bink_put_pixels(c, dst, prev, stride,\n                                      ref_start, ref_end);\n                if (ret < 0)\n                    return ret;\n                memset(dctblock, 0, sizeof(*dctblock) * 64);\n                dctblock[0] = get_value(c, BINK_SRC_INTER_DC);\n                read_dct_coeffs(bc, dctblock, bink_scan, bink_inter_quant, -1);\n                c->binkdsp.idct_add(dst, stride, dctblock);\n                break;\n            case PATTERN_BLOCK:\n                for (i = 0; i < 2; i++)\n                    col[i] = get_value(c, BINK_SRC_COLORS);\n                for (i = 0; i < 8; i++) {\n                    v = get_value(c, BINK_SRC_PATTERN);\n                    for (j = 0; j < 8; j++, v >>= 1)\n                        dst[i*stride + j] = col[v & 1];\n                }\n                break;\n            case RAW_BLOCK:\n                for (i = 0; i < 8; i++)\n                    memcpy(dst + i*stride, c->bundle[BINK_SRC_COLORS].cur_ptr + i*8, 8);\n                c->bundle[BINK_SRC_COLORS].cur_ptr += 64;\n                break;\n            default:\n                av_log(c->avctx, AV_LOG_ERROR, "Unknown block type %d\\n", blk);\n                return AVERROR_INVALIDDATA;\n            }\n        }\n    }\n    if (bitstream_tell(bc) & 0x1F)\n        bitstream_skip(bc, 32 - (bitstream_tell(bc) & 0x1F));\n    return 0;\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n    if (!n)\n        return 0;\n    if (n > bc->bits_left) {\n        refill_32(bc);\n        if (bc->bits_left < 32)\n            bc->bits_left = n;\n    }\n    return get_val(bc, n);\n}', 'static inline uint64_t get_val(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n    uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);\n    bc->bits >>= n;\n#else\n    uint64_t ret = bc->bits >> (64 - n);\n    bc->bits <<= n;\n#endif\n    bc->bits_left -= n;\n    return ret;\n}']