libavcodec/mlpdec.c:1120: error: Integer Overflow L2
  ([0, +oo] - 1):unsigned32 by call to `bitstream_read_bit`.

libavcodec/mlpdec.c:1125:15: Call
1123.         bitstream_skip(&bc, 1);
1124. 
1125.         end = bitstream_read(&bc, 12) * 2;
                    ^
1126. 
1127.         substr_header_size += 2;

libavcodec/bitstream.h:183:1: Parameter `bc->bits_left`
  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/mlpdec.c:1120:29: Call
1118.         int extraword_present, checkdata_present, end, nonrestart_substr;
1119. 
1120.         extraword_present = bitstream_read_bit(&bc);
                                  ^
1121.         nonrestart_substr = bitstream_read_bit(&bc);
1122.         checkdata_present = bitstream_read_bit(&bc);

libavcodec/bitstream.h:145:1: Parameter `bc->bits_left`
  143. 
  144. /* Return one bit from the buffer. */
  145. static inline unsigned bitstream_read_bit(BitstreamContext *bc)
       ^
  146. {
  147.     if (!bc->bits_left)

libavcodec/bitstream.h:150:12: Call
  148.         refill_64(bc);
  149. 
  150.     return get_val(bc, 1);
                  ^
  151. }
  152. 

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: ([0, +oo] - 1):unsigned32 by call to `bitstream_read_bit` 
    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 read_access_unit(AVCodecContext *avctx, void* data,\n                            int *got_frame_ptr, AVPacket *avpkt)\n{\n    const uint8_t *buf = avpkt->data;\n    int buf_size = avpkt->size;\n    MLPDecodeContext *m = avctx->priv_data;\n    BitstreamContext bc;\n    unsigned int length, substr;\n    unsigned int substream_start;\n    unsigned int header_size = 4;\n    unsigned int substr_header_size = 0;\n    uint8_t substream_parity_present[MAX_SUBSTREAMS];\n    uint16_t substream_data_len[MAX_SUBSTREAMS];\n    uint8_t parity_bits;\n    int ret;\n    if (buf_size < 4)\n        return 0;\n    length = (AV_RB16(buf) & 0xfff) * 2;\n    if (length < 4 || length > buf_size)\n        return AVERROR_INVALIDDATA;\n    bitstream_init(&bc, (buf + 4), (length - 4) * 8);\n    m->is_major_sync_unit = 0;\n    if (bitstream_peek(&bc, 31) == (0xf8726fba >> 1)) {\n        if (read_major_sync(m, &bc) < 0)\n            goto error;\n        m->is_major_sync_unit = 1;\n        header_size += m->major_sync_header_size;\n    }\n    if (!m->params_valid) {\n        av_log(m->avctx, AV_LOG_WARNING,\n               "Stream parameters not seen; skipping frame.\\n");\n        *got_frame_ptr = 0;\n        return length;\n    }\n    substream_start = 0;\n    for (substr = 0; substr < m->num_substreams; substr++) {\n        int extraword_present, checkdata_present, end, nonrestart_substr;\n        extraword_present = bitstream_read_bit(&bc);\n        nonrestart_substr = bitstream_read_bit(&bc);\n        checkdata_present = bitstream_read_bit(&bc);\n        bitstream_skip(&bc, 1);\n        end = bitstream_read(&bc, 12) * 2;\n        substr_header_size += 2;\n        if (extraword_present) {\n            if (m->avctx->codec_id == AV_CODEC_ID_MLP) {\n                av_log(m->avctx, AV_LOG_ERROR, "There must be no extraword for MLP.\\n");\n                goto error;\n            }\n            bitstream_skip(&bc, 16);\n            substr_header_size += 2;\n        }\n        if (!(nonrestart_substr ^ m->is_major_sync_unit)) {\n            av_log(m->avctx, AV_LOG_ERROR, "Invalid nonrestart_substr.\\n");\n            goto error;\n        }\n        if (end + header_size + substr_header_size > length) {\n            av_log(m->avctx, AV_LOG_ERROR,\n                   "Indicated length of substream %d data goes off end of "\n                   "packet.\\n", substr);\n            end = length - header_size - substr_header_size;\n        }\n        if (end < substream_start) {\n            av_log(avctx, AV_LOG_ERROR,\n                   "Indicated end offset of substream %d data "\n                   "is smaller than calculated start offset.\\n",\n                   substr);\n            goto error;\n        }\n        if (substr > m->max_decoded_substream)\n            continue;\n        substream_parity_present[substr] = checkdata_present;\n        substream_data_len[substr] = end - substream_start;\n        substream_start = end;\n    }\n    parity_bits  = ff_mlp_calculate_parity(buf, 4);\n    parity_bits ^= ff_mlp_calculate_parity(buf + header_size, substr_header_size);\n    if ((((parity_bits >> 4) ^ parity_bits) & 0xF) != 0xF) {\n        av_log(avctx, AV_LOG_ERROR, "Parity check failed.\\n");\n        goto error;\n    }\n    buf += header_size + substr_header_size;\n    for (substr = 0; substr <= m->max_decoded_substream; substr++) {\n        SubStream *s = &m->substream[substr];\n        bitstream_init(&bc, buf, substream_data_len[substr] * 8);\n        m->matrix_changed = 0;\n        memset(m->filter_changed, 0, sizeof(m->filter_changed));\n        s->blockpos = 0;\n        do {\n            if (bitstream_read_bit(&bc)) {\n                if (bitstream_read_bit(&bc)) {\n                    if (read_restart_header(m, &bc, buf, substr) < 0)\n                        goto next_substr;\n                    s->restart_seen = 1;\n                }\n                if (!s->restart_seen)\n                    goto next_substr;\n                if (read_decoding_params(m, &bc, substr) < 0)\n                    goto next_substr;\n            }\n            if (!s->restart_seen)\n                goto next_substr;\n            if ((ret = read_block_data(m, &bc, substr)) < 0)\n                return ret;\n            if (bitstream_tell(&bc) >= substream_data_len[substr] * 8)\n                goto substream_length_mismatch;\n        } while (!bitstream_read_bit(&bc));\n        bitstream_skip(&bc, (-bitstream_tell(&bc)) & 15);\n        if (substream_data_len[substr] * 8 - bitstream_tell(&bc) >= 32) {\n            int shorten_by;\n            if (bitstream_read(&bc, 16) != 0xD234)\n                return AVERROR_INVALIDDATA;\n            shorten_by = bitstream_read(&bc, 16);\n            if      (m->avctx->codec_id == AV_CODEC_ID_TRUEHD && shorten_by  & 0x2000)\n                s->blockpos -= FFMIN(shorten_by & 0x1FFF, s->blockpos);\n            else if (m->avctx->codec_id == AV_CODEC_ID_MLP    && shorten_by != 0xD234)\n                return AVERROR_INVALIDDATA;\n            if (substr == m->max_decoded_substream)\n                av_log(m->avctx, AV_LOG_INFO, "End of stream indicated.\\n");\n        }\n        if (substream_parity_present[substr]) {\n            uint8_t parity, checksum;\n            if (substream_data_len[substr] * 8 - bitstream_tell(&bc) != 16)\n                goto substream_length_mismatch;\n            parity   = ff_mlp_calculate_parity(buf, substream_data_len[substr] - 2);\n            checksum = ff_mlp_checksum8       (buf, substream_data_len[substr] - 2);\n            if ((bitstream_read(&bc, 8) ^ parity) != 0xa9)\n                av_log(m->avctx, AV_LOG_ERROR, "Substream %d parity check failed.\\n", substr);\n            if (bitstream_read(&bc, 8) != checksum)\n                av_log(m->avctx, AV_LOG_ERROR, "Substream %d checksum failed.\\n"    , substr);\n        }\n        if (substream_data_len[substr] * 8 != bitstream_tell(&bc))\n            goto substream_length_mismatch;\nnext_substr:\n        if (!s->restart_seen)\n            av_log(m->avctx, AV_LOG_ERROR,\n                   "No restart header present in substream %d.\\n", substr);\n        buf += substream_data_len[substr];\n    }\n    rematrix_channels(m, m->max_decoded_substream);\n    if ((ret = output_data(m, m->max_decoded_substream, data, got_frame_ptr)) < 0)\n        return ret;\n    return length;\nsubstream_length_mismatch:\n    av_log(m->avctx, AV_LOG_ERROR, "substream %d length mismatch\\n", substr);\n    return AVERROR_INVALIDDATA;\nerror:\n    m->params_valid = 0;\n    return AVERROR_INVALIDDATA;\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 unsigned bitstream_read_bit(BitstreamContext *bc)\n{\n    if (!bc->bits_left)\n        refill_64(bc);\n    return get_val(bc, 1);\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}']