libavcodec/mlpdec.c:548: error: Integer Overflow L1
  (0 - 1):unsigned64 by call to `av_get_channel_layout_channel_index`.

libavcodec/mlpdec.c:546:32: Call
544.         int ch_assign = bitstream_read(bc, 6);
545.         if (m->avctx->codec_id == AV_CODEC_ID_TRUEHD) {
546.             uint64_t channel = thd_channel_layout_extract_channel(s->ch_layout,
                                    ^
547.                                                                   ch_assign);
548.             ch_assign = av_get_channel_layout_channel_index(s->ch_layout,

libavcodec/mlpdec.c:187:9: Assignment
  185. 
  186.     if (av_get_channel_layout_nb_channels(channel_layout) <= index)
  187.         return 0;
               ^
  188. 
  189.     for (i = 0; i < FF_ARRAY_ELEMS(thd_channel_order); i++)

libavcodec/mlpdec.c:546:13: Assignment
544.         int ch_assign = bitstream_read(bc, 6);
545.         if (m->avctx->codec_id == AV_CODEC_ID_TRUEHD) {
546.             uint64_t channel = thd_channel_layout_extract_channel(s->ch_layout,
                 ^
547.                                                                   ch_assign);
548.             ch_assign = av_get_channel_layout_channel_index(s->ch_layout,

libavcodec/mlpdec.c:548:25: Call
546.             uint64_t channel = thd_channel_layout_extract_channel(s->ch_layout,
547.                                                                   ch_assign);
548.             ch_assign = av_get_channel_layout_channel_index(s->ch_layout,
                             ^
549.                                                             channel);
550.         }

libavutil/channel_layout.c:202:1: <LHS trace>
200. }
201. 
202. int av_get_channel_layout_channel_index(uint64_t channel_layout,
     ^
203.                                         uint64_t channel)
204. {

libavutil/channel_layout.c:202:1: Parameter `channel`
  200. }
  201. 
  202. int av_get_channel_layout_channel_index(uint64_t channel_layout,
       ^
  203.                                         uint64_t channel)
  204. {

libavutil/channel_layout.c:208:5: Binary operation: (0 - 1):unsigned64 by call to `av_get_channel_layout_channel_index` 
  206.         av_get_channel_layout_nb_channels(channel) != 1)
  207.         return AVERROR(EINVAL);
  208.     channel_layout &= channel - 1;
           ^
  209.     return av_get_channel_layout_nb_channels(channel_layout);
  210. }

int av_get_channel_layout_channel_index(uint64_t channel_layout,
                                        uint64_t channel)
{
    if (!(channel_layout & channel) ||
        av_get_channel_layout_nb_channels(channel) != 1)
        return AVERROR(EINVAL);
    channel_layout &= channel - 1;
    return av_get_channel_layout_nb_channels(channel_layout);
}
['static int read_restart_header(MLPDecodeContext *m, BitstreamContext *bc,\n                               const uint8_t *buf, unsigned int substr)\n{\n    SubStream *s = &m->substream[substr];\n    unsigned int ch;\n    int sync_word, tmp;\n    uint8_t checksum;\n    uint8_t lossless_check;\n    int start_count = bitstream_tell(bc);\n    int min_channel, max_channel, max_matrix_channel;\n    const int std_max_matrix_channel = m->avctx->codec_id == AV_CODEC_ID_MLP\n                                     ? MAX_MATRIX_CHANNEL_MLP\n                                     : MAX_MATRIX_CHANNEL_TRUEHD;\n    sync_word = bitstream_read(bc, 13);\n    if (sync_word != 0x31ea >> 1) {\n        av_log(m->avctx, AV_LOG_ERROR,\n               "restart header sync incorrect (got 0x%04x)\\n", sync_word);\n        return AVERROR_INVALIDDATA;\n    }\n    s->noise_type = bitstream_read_bit(bc);\n    if (m->avctx->codec_id == AV_CODEC_ID_MLP && s->noise_type) {\n        av_log(m->avctx, AV_LOG_ERROR, "MLP must have 0x31ea sync word.\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    bitstream_skip(bc, 16);\n    min_channel        = bitstream_read(bc, 4);\n    max_channel        = bitstream_read(bc, 4);\n    max_matrix_channel = bitstream_read(bc, 4);\n    if (max_matrix_channel > std_max_matrix_channel) {\n        av_log(m->avctx, AV_LOG_ERROR,\n               "Max matrix channel cannot be greater than %d.\\n",\n               max_matrix_channel);\n        return AVERROR_INVALIDDATA;\n    }\n    if (max_channel != max_matrix_channel) {\n        av_log(m->avctx, AV_LOG_ERROR,\n               "Max channel must be equal max matrix channel.\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    if (s->max_channel > MAX_MATRIX_CHANNEL_MLP && !s->noise_type) {\n        avpriv_request_sample(m->avctx,\n                              "%d channels (more than the "\n                              "maximum supported by the decoder)",\n                              s->max_channel + 2);\n        return AVERROR_PATCHWELCOME;\n    }\n    if (min_channel > max_channel) {\n        av_log(m->avctx, AV_LOG_ERROR,\n               "Substream min channel cannot be greater than max channel.\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    s->min_channel        = min_channel;\n    s->max_channel        = max_channel;\n    s->max_matrix_channel = max_matrix_channel;\n    if (m->avctx->request_channel_layout && (s->ch_layout & m->avctx->request_channel_layout) ==\n        m->avctx->request_channel_layout && m->max_decoded_substream > substr) {\n        av_log(m->avctx, AV_LOG_DEBUG,\n               "Extracting %d-channel downmix (0x%"PRIx64") from substream %d. "\n               "Further substreams will be skipped.\\n",\n               s->max_channel + 1, s->ch_layout, substr);\n        m->max_decoded_substream = substr;\n    }\n    s->noise_shift   = bitstream_read(bc,  4);\n    s->noisegen_seed = bitstream_read(bc, 23);\n    bitstream_skip(bc, 19);\n    s->data_check_present = bitstream_read_bit(bc);\n    lossless_check = bitstream_read(bc, 8);\n    if (substr == m->max_decoded_substream\n        && s->lossless_check_data != 0xffffffff) {\n        tmp = xor_32_to_8(s->lossless_check_data);\n        if (tmp != lossless_check)\n            av_log(m->avctx, AV_LOG_WARNING,\n                   "Lossless check failed - expected %02x, calculated %02x.\\n",\n                   lossless_check, tmp);\n    }\n    bitstream_skip(bc, 16);\n    memset(s->ch_assign, 0, sizeof(s->ch_assign));\n    for (ch = 0; ch <= s->max_matrix_channel; ch++) {\n        int ch_assign = bitstream_read(bc, 6);\n        if (m->avctx->codec_id == AV_CODEC_ID_TRUEHD) {\n            uint64_t channel = thd_channel_layout_extract_channel(s->ch_layout,\n                                                                  ch_assign);\n            ch_assign = av_get_channel_layout_channel_index(s->ch_layout,\n                                                            channel);\n        }\n        if (ch_assign < 0 || ch_assign > s->max_matrix_channel) {\n            avpriv_request_sample(m->avctx,\n                                  "Assignment of matrix channel %d to invalid output channel %d",\n                                  ch, ch_assign);\n            return AVERROR_PATCHWELCOME;\n        }\n        s->ch_assign[ch_assign] = ch;\n    }\n    checksum = ff_mlp_restart_checksum(buf, bitstream_tell(bc) - start_count);\n    if (checksum != bitstream_read(bc, 8))\n        av_log(m->avctx, AV_LOG_ERROR, "restart header checksum error\\n");\n    s->param_presence_flags   = 0xff;\n    s->num_primitive_matrices = 0;\n    s->blocksize              = 8;\n    s->lossless_check_data    = 0;\n    memset(s->output_shift   , 0, sizeof(s->output_shift   ));\n    memset(s->quant_step_size, 0, sizeof(s->quant_step_size));\n    for (ch = s->min_channel; ch <= s->max_channel; ch++) {\n        ChannelParams *cp = &s->channel_params[ch];\n        cp->filter_params[FIR].order = 0;\n        cp->filter_params[IIR].order = 0;\n        cp->filter_params[FIR].shift = 0;\n        cp->filter_params[IIR].shift = 0;\n        cp->huff_offset      = 0;\n        cp->sign_huff_offset = -(1 << 23);\n        cp->codebook         = 0;\n        cp->huff_lsbs        = 24;\n    }\n    if (substr == m->max_decoded_substream) {\n        m->avctx->channels       = s->max_matrix_channel + 1;\n        m->avctx->channel_layout = s->ch_layout;\n        m->dsp.mlp_pack_output = m->dsp.mlp_select_pack_output(s->ch_assign,\n                                                               s->output_shift,\n                                                               s->max_matrix_channel,\n                                                               m->avctx->sample_fmt == AV_SAMPLE_FMT_S32);\n    }\n    return 0;\n}', 'static uint64_t thd_channel_layout_extract_channel(uint64_t channel_layout,\n                                                   int index)\n{\n    int i;\n    if (av_get_channel_layout_nb_channels(channel_layout) <= index)\n        return 0;\n    for (i = 0; i < FF_ARRAY_ELEMS(thd_channel_order); i++)\n        if (channel_layout & thd_channel_order[i] && !index--)\n            return thd_channel_order[i];\n    return 0;\n}', 'int av_get_channel_layout_channel_index(uint64_t channel_layout,\n                                        uint64_t channel)\n{\n    if (!(channel_layout & channel) ||\n        av_get_channel_layout_nb_channels(channel) != 1)\n        return AVERROR(EINVAL);\n    channel_layout &= channel - 1;\n    return av_get_channel_layout_nb_channels(channel_layout);\n}']