libavcodec/ac3enc.c:2238: error: Buffer Overrun L2
  Offset: [min(-1, `avctx->priv_data->lfe_channel`), max(8, `avctx->priv_data->lfe_channel`)] Size: 7 by call to `set_bandwidth`.

libavcodec/ac3enc.c:2191:9: Parameter `avctx->priv_data->lfe_channel`
2189.  * Initialize the encoder.
2190.  */
2191. av_cold int ff_ac3_encode_init(AVCodecContext *avctx)
              ^
2192. {
2193.     AC3EncodeContext *s = avctx->priv_data;

libavcodec/ac3enc.c:2204:11: Call
2202.     ff_ac3_common_init();
2203. 
2204.     ret = validate_options(s);
                ^
2205.     if (ret)
2206.         return ret;

libavcodec/ac3enc.c:1894:1: Parameter `s->lfe_channel`
  1892. 
  1893. 
  1894. static av_cold int validate_options(AC3EncodeContext *s)
        ^
  1895. {
  1896.     AVCodecContext *avctx = s->avctx;

libavcodec/ac3enc.c:1905:11: Call
  1903.                                       "might be incorrect.\n");
  1904.     }
  1905.     ret = set_channel_info(s, avctx->channels, &avctx->channel_layout);
                  ^
  1906.     if (ret) {
  1907.         av_log(avctx, AV_LOG_ERROR, "invalid channel layout\n");

libavcodec/ac3enc.c:1849:1: Parameter `s->lfe_channel`
    1847.  * Set channel information during initialization.
    1848.  */
    1849. static av_cold int set_channel_info(AC3EncodeContext *s, int channels,
          ^
    1850.                                     int64_t *channel_layout)
    1851. {

libavcodec/ac3enc.c:2238:5: Call
2236.         s->output_frame_header = ac3_output_frame_header;
2237. 
2238.     set_bandwidth(s);
          ^
2239. 
2240.     exponent_init(s);

libavcodec/ac3enc.c:2021:1: <Offset trace>
2019.  * default value will be used.
2020.  */
2021. static av_cold void set_bandwidth(AC3EncodeContext *s)
      ^
2022. {
2023.     int blk, ch;

libavcodec/ac3enc.c:2021:1: Parameter `s->lfe_channel`
  2019.  * default value will be used.
  2020.  */
  2021. static av_cold void set_bandwidth(AC3EncodeContext *s)
        ^
  2022. {
  2023.     int blk, ch;

libavcodec/ac3enc.c:2021:1: <Length trace>
2019.  * default value will be used.
2020.  */
2021. static av_cold void set_bandwidth(AC3EncodeContext *s)
      ^
2022. {
2023.     int blk, ch;

libavcodec/ac3enc.c:2021:1: Parameter `s->start_freq[*]`
  2019.  * default value will be used.
  2020.  */
  2021. static av_cold void set_bandwidth(AC3EncodeContext *s)
        ^
  2022. {
  2023.     int blk, ch;

libavcodec/ac3enc.c:2044:9: Array access: Offset: [min(-1, avctx->priv_data->lfe_channel), max(8, avctx->priv_data->lfe_channel)] Size: 7 by call to `set_bandwidth` 
  2042.     /* LFE channel always has 7 coefs */
  2043.     if (s->lfe_on) {
  2044.         s->start_freq[s->lfe_channel] = 0;
                ^
  2045.         for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
  2046.             s->blocks[blk].end_freq[ch] = 7;

static av_cold void set_bandwidth(AC3EncodeContext *s)
{
    int blk, ch;
    int av_uninit(cpl_start);
    if (s->cutoff) {
        int fbw_coeffs;
        fbw_coeffs     = s->cutoff * 2 * AC3_MAX_COEFS / s->sample_rate;
        s->bandwidth_code = av_clip((fbw_coeffs - 73) / 3, 0, 60);
    } else {
        s->bandwidth_code = ac3_bandwidth_tab[s->fbw_channels-1][s->bit_alloc.sr_code][s->frame_size_code/2];
    }
    for (ch = 1; ch <= s->fbw_channels; ch++) {
        s->start_freq[ch] = 0;
        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
            s->blocks[blk].end_freq[ch] = s->bandwidth_code * 3 + 73;
    }
    if (s->lfe_on) {
        s->start_freq[s->lfe_channel] = 0;
        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
            s->blocks[blk].end_freq[ch] = 7;
    }
    if (s->cpl_enabled) {
        if (s->options.cpl_start >= 0) {
            cpl_start = s->options.cpl_start;
        } else {
            cpl_start = ac3_coupling_start_tab[s->channel_mode-2][s->bit_alloc.sr_code][s->frame_size_code/2];
            if (cpl_start < 0)
                s->cpl_enabled = 0;
        }
    }
    if (s->cpl_enabled) {
        int i, cpl_start_band, cpl_end_band;
        uint8_t *cpl_band_sizes = s->cpl_band_sizes;
        cpl_end_band   = s->bandwidth_code / 4 + 3;
        cpl_start_band = av_clip(cpl_start, 0, FFMIN(cpl_end_band-1, 15));
        s->num_cpl_subbands = cpl_end_band - cpl_start_band;
        s->num_cpl_bands = 1;
        *cpl_band_sizes  = 12;
        for (i = cpl_start_band + 1; i < cpl_end_band; i++) {
            if (ff_eac3_default_cpl_band_struct[i]) {
                *cpl_band_sizes += 12;
            } else {
                s->num_cpl_bands++;
                cpl_band_sizes++;
                *cpl_band_sizes = 12;
            }
        }
        s->start_freq[CPL_CH] = cpl_start_band * 12 + 37;
        s->cpl_end_freq       = cpl_end_band   * 12 + 37;
        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)
            s->blocks[blk].end_freq[CPL_CH] = s->cpl_end_freq;
    }
}
['int ff_ac3_encode_init(AVCodecContext *avctx)\n{\n    AC3EncodeContext *s = avctx->priv_data;\n    int ret, frame_size_58;\n    s->avctx = avctx;\n    s->eac3 = avctx->codec_id == CODEC_ID_EAC3;\n    avctx->frame_size = AC3_FRAME_SIZE;\n    ff_ac3_common_init();\n    ret = validate_options(s);\n    if (ret)\n        return ret;\n    s->bitstream_mode = avctx->audio_service_type;\n    if (s->bitstream_mode == AV_AUDIO_SERVICE_TYPE_KARAOKE)\n        s->bitstream_mode = 0x7;\n    s->bits_written    = 0;\n    s->samples_written = 0;\n    frame_size_58 = (( s->frame_size    >> 2) + ( s->frame_size    >> 4)) << 1;\n    s->crc_inv[0] = pow_poly((CRC16_POLY >> 1), (8 * frame_size_58) - 16, CRC16_POLY);\n    if (s->bit_alloc.sr_code == 1) {\n        frame_size_58 = (((s->frame_size+2) >> 2) + ((s->frame_size+2) >> 4)) << 1;\n        s->crc_inv[1] = pow_poly((CRC16_POLY >> 1), (8 * frame_size_58) - 16, CRC16_POLY);\n    }\n    if (CONFIG_AC3_FIXED_ENCODER && s->fixed_point) {\n        s->mdct_end                     = ff_ac3_fixed_mdct_end;\n        s->mdct_init                    = ff_ac3_fixed_mdct_init;\n        s->allocate_sample_buffers      = ff_ac3_fixed_allocate_sample_buffers;\n    } else if (CONFIG_AC3_ENCODER || CONFIG_EAC3_ENCODER) {\n        s->mdct_end                     = ff_ac3_float_mdct_end;\n        s->mdct_init                    = ff_ac3_float_mdct_init;\n        s->allocate_sample_buffers      = ff_ac3_float_allocate_sample_buffers;\n    }\n    if (CONFIG_EAC3_ENCODER && s->eac3)\n        s->output_frame_header = ff_eac3_output_frame_header;\n    else\n        s->output_frame_header = ac3_output_frame_header;\n    set_bandwidth(s);\n    exponent_init(s);\n    bit_alloc_init(s);\n    ret = s->mdct_init(s);\n    if (ret)\n        goto init_fail;\n    ret = allocate_buffers(s);\n    if (ret)\n        goto init_fail;\n    avctx->coded_frame= avcodec_alloc_frame();\n    dsputil_init(&s->dsp, avctx);\n    ff_ac3dsp_init(&s->ac3dsp, avctx->flags & CODEC_FLAG_BITEXACT);\n    dprint_options(s);\n    return 0;\ninit_fail:\n    ff_ac3_encode_close(avctx);\n    return ret;\n}', 'static av_cold int validate_options(AC3EncodeContext *s)\n{\n    AVCodecContext *avctx = s->avctx;\n    int i, ret, max_sr;\n    if (!avctx->channel_layout) {\n        av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The "\n                                      "encoder will guess the layout, but it "\n                                      "might be incorrect.\\n");\n    }\n    ret = set_channel_info(s, avctx->channels, &avctx->channel_layout);\n    if (ret) {\n        av_log(avctx, AV_LOG_ERROR, "invalid channel layout\\n");\n        return ret;\n    }\n    max_sr = s->eac3 ? 2 : 8;\n    for (i = 0; i <= max_sr; i++) {\n        if ((ff_ac3_sample_rate_tab[i % 3] >> (i / 3)) == avctx->sample_rate)\n            break;\n    }\n    if (i > max_sr) {\n        av_log(avctx, AV_LOG_ERROR, "invalid sample rate\\n");\n        return AVERROR(EINVAL);\n    }\n    s->sample_rate        = avctx->sample_rate;\n    s->bit_alloc.sr_shift = i / 3;\n    s->bit_alloc.sr_code  = i % 3;\n    s->bitstream_id       = s->eac3 ? 16 : 8 + s->bit_alloc.sr_shift;\n    if (s->eac3) {\n        int max_br, min_br, wpf, min_br_dist, min_br_code;\n        max_br = 2048 * s->sample_rate / AC3_FRAME_SIZE * 16;\n        min_br = ((s->sample_rate + (AC3_FRAME_SIZE-1)) / AC3_FRAME_SIZE) * 16;\n        if (avctx->bit_rate < min_br || avctx->bit_rate > max_br) {\n            av_log(avctx, AV_LOG_ERROR, "invalid bit rate. must be %d to %d "\n                   "for this sample rate\\n", min_br, max_br);\n            return AVERROR(EINVAL);\n        }\n        wpf = (avctx->bit_rate / 16) * AC3_FRAME_SIZE / s->sample_rate;\n        av_assert1(wpf > 0 && wpf <= 2048);\n        min_br_code = -1;\n        min_br_dist = INT_MAX;\n        for (i = 0; i < 19; i++) {\n            int br_dist = abs(ff_ac3_bitrate_tab[i] * 1000 - avctx->bit_rate);\n            if (br_dist < min_br_dist) {\n                min_br_dist = br_dist;\n                min_br_code = i;\n            }\n        }\n        s->frame_size_code = min_br_code << 1;\n        while (wpf > 1 && wpf * s->sample_rate / AC3_FRAME_SIZE * 16 > avctx->bit_rate)\n            wpf--;\n        s->frame_size_min = 2 * wpf;\n    } else {\n        for (i = 0; i < 19; i++) {\n            if ((ff_ac3_bitrate_tab[i] >> s->bit_alloc.sr_shift)*1000 == avctx->bit_rate)\n                break;\n        }\n        if (i == 19) {\n            av_log(avctx, AV_LOG_ERROR, "invalid bit rate\\n");\n            return AVERROR(EINVAL);\n        }\n        s->frame_size_code = i << 1;\n        s->frame_size_min  = 2 * ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code];\n    }\n    s->bit_rate   = avctx->bit_rate;\n    s->frame_size = s->frame_size_min;\n    if (avctx->cutoff < 0) {\n        av_log(avctx, AV_LOG_ERROR, "invalid cutoff frequency\\n");\n        return AVERROR(EINVAL);\n    }\n    s->cutoff = avctx->cutoff;\n    if (s->cutoff > (s->sample_rate >> 1))\n        s->cutoff = s->sample_rate >> 1;\n    if ((avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_KARAOKE &&\n         avctx->channels == 1) ||\n        ((avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_COMMENTARY ||\n          avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_EMERGENCY  ||\n          avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_VOICE_OVER)\n         && avctx->channels > 1)) {\n        av_log(avctx, AV_LOG_ERROR, "invalid audio service type for the "\n                                    "specified number of channels\\n");\n        return AVERROR(EINVAL);\n    }\n    if (!s->eac3) {\n        ret = ff_ac3_validate_metadata(s);\n        if (ret)\n            return ret;\n    }\n    s->rematrixing_enabled = s->options.stereo_rematrixing &&\n                             (s->channel_mode == AC3_CHMODE_STEREO);\n    s->cpl_enabled = s->options.channel_coupling &&\n                     s->channel_mode >= AC3_CHMODE_STEREO && !s->fixed_point;\n    return 0;\n}', 'static av_cold int set_channel_info(AC3EncodeContext *s, int channels,\n                                    int64_t *channel_layout)\n{\n    int ch_layout;\n    if (channels < 1 || channels > AC3_MAX_CHANNELS)\n        return AVERROR(EINVAL);\n    if ((uint64_t)*channel_layout > 0x7FF)\n        return AVERROR(EINVAL);\n    ch_layout = *channel_layout;\n    if (!ch_layout)\n        ch_layout = avcodec_guess_channel_layout(channels, CODEC_ID_AC3, NULL);\n    s->lfe_on       = !!(ch_layout & AV_CH_LOW_FREQUENCY);\n    s->channels     = channels;\n    s->fbw_channels = channels - s->lfe_on;\n    s->lfe_channel  = s->lfe_on ? s->fbw_channels + 1 : -1;\n    if (s->lfe_on)\n        ch_layout -= AV_CH_LOW_FREQUENCY;\n    switch (ch_layout) {\n    case AV_CH_LAYOUT_MONO:           s->channel_mode = AC3_CHMODE_MONO;   break;\n    case AV_CH_LAYOUT_STEREO:         s->channel_mode = AC3_CHMODE_STEREO; break;\n    case AV_CH_LAYOUT_SURROUND:       s->channel_mode = AC3_CHMODE_3F;     break;\n    case AV_CH_LAYOUT_2_1:            s->channel_mode = AC3_CHMODE_2F1R;   break;\n    case AV_CH_LAYOUT_4POINT0:        s->channel_mode = AC3_CHMODE_3F1R;   break;\n    case AV_CH_LAYOUT_QUAD:\n    case AV_CH_LAYOUT_2_2:            s->channel_mode = AC3_CHMODE_2F2R;   break;\n    case AV_CH_LAYOUT_5POINT0:\n    case AV_CH_LAYOUT_5POINT0_BACK:   s->channel_mode = AC3_CHMODE_3F2R;   break;\n    default:\n        return AVERROR(EINVAL);\n    }\n    s->has_center   = (s->channel_mode & 0x01) && s->channel_mode != AC3_CHMODE_MONO;\n    s->has_surround =  s->channel_mode & 0x04;\n    s->channel_map  = ff_ac3_enc_channel_map[s->channel_mode][s->lfe_on];\n    *channel_layout = ch_layout;\n    if (s->lfe_on)\n        *channel_layout |= AV_CH_LOW_FREQUENCY;\n    return 0;\n}', 'static av_cold void set_bandwidth(AC3EncodeContext *s)\n{\n    int blk, ch;\n    int av_uninit(cpl_start);\n    if (s->cutoff) {\n        int fbw_coeffs;\n        fbw_coeffs     = s->cutoff * 2 * AC3_MAX_COEFS / s->sample_rate;\n        s->bandwidth_code = av_clip((fbw_coeffs - 73) / 3, 0, 60);\n    } else {\n        s->bandwidth_code = ac3_bandwidth_tab[s->fbw_channels-1][s->bit_alloc.sr_code][s->frame_size_code/2];\n    }\n    for (ch = 1; ch <= s->fbw_channels; ch++) {\n        s->start_freq[ch] = 0;\n        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)\n            s->blocks[blk].end_freq[ch] = s->bandwidth_code * 3 + 73;\n    }\n    if (s->lfe_on) {\n        s->start_freq[s->lfe_channel] = 0;\n        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)\n            s->blocks[blk].end_freq[ch] = 7;\n    }\n    if (s->cpl_enabled) {\n        if (s->options.cpl_start >= 0) {\n            cpl_start = s->options.cpl_start;\n        } else {\n            cpl_start = ac3_coupling_start_tab[s->channel_mode-2][s->bit_alloc.sr_code][s->frame_size_code/2];\n            if (cpl_start < 0)\n                s->cpl_enabled = 0;\n        }\n    }\n    if (s->cpl_enabled) {\n        int i, cpl_start_band, cpl_end_band;\n        uint8_t *cpl_band_sizes = s->cpl_band_sizes;\n        cpl_end_band   = s->bandwidth_code / 4 + 3;\n        cpl_start_band = av_clip(cpl_start, 0, FFMIN(cpl_end_band-1, 15));\n        s->num_cpl_subbands = cpl_end_band - cpl_start_band;\n        s->num_cpl_bands = 1;\n        *cpl_band_sizes  = 12;\n        for (i = cpl_start_band + 1; i < cpl_end_band; i++) {\n            if (ff_eac3_default_cpl_band_struct[i]) {\n                *cpl_band_sizes += 12;\n            } else {\n                s->num_cpl_bands++;\n                cpl_band_sizes++;\n                *cpl_band_sizes = 12;\n            }\n        }\n        s->start_freq[CPL_CH] = cpl_start_band * 12 + 37;\n        s->cpl_end_freq       = cpl_end_band   * 12 + 37;\n        for (blk = 0; blk < AC3_MAX_BLOCKS; blk++)\n            s->blocks[blk].end_freq[CPL_CH] = s->cpl_end_freq;\n    }\n}']