Revision c9f6eab1

View differences:

libavcodec/ac3dec.c
207 207
    }
208 208
    s->downmixed = 1;
209 209

  
210
    /* allocate context input buffer */
211
    if (avctx->error_recognition >= FF_ER_CAREFUL) {
212
        s->input_buffer = av_mallocz(AC3_FRAME_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
213
        if (!s->input_buffer)
214
            return AVERROR(ENOMEM);
215
    }
216

  
217 210
    avctx->sample_fmt = AV_SAMPLE_FMT_S16;
218 211
    return 0;
219 212
}
......
1312 1305
    int blk, ch, err;
1313 1306
    const uint8_t *channel_map;
1314 1307
    const float *output[AC3_MAX_CHANNELS];
1308
    // if it seems to be byte-swapped AC-3 (aka DNET)
1309
    int is_swapped = buf_size >= 2 && AV_RB16(buf) == 0x770B;
1315 1310

  
1316 1311
    /* initialize the GetBitContext with the start of valid AC-3 Frame */
1317
    if (s->input_buffer) {
1312
    if (is_swapped || avctx->error_recognition >= FF_ER_CAREFUL) {
1313
        /* allocate context input buffer */
1314
        if (!s->input_buffer)
1315
            s->input_buffer = av_mallocz(AC3_FRAME_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
1316
        if (!s->input_buffer)
1317
            return AVERROR(ENOMEM);
1318

  
1318 1319
        /* copy input buffer to decoder context to avoid reading past the end
1319 1320
           of the buffer, which can be caused by a damaged input stream. */
1321
        if (is_swapped) {
1322
            int cnt = FFMIN(buf_size, AC3_FRAME_BUFFER_SIZE) >> 1;
1323
            s->dsp.bswap16_buf(s->input_buffer, buf, cnt);
1324
        } else
1320 1325
        memcpy(s->input_buffer, buf, FFMIN(buf_size, AC3_FRAME_BUFFER_SIZE));
1321
        init_get_bits(&s->gbc, s->input_buffer, buf_size * 8);
1322
    } else {
1323
        init_get_bits(&s->gbc, buf, buf_size * 8);
1326
        buf = s->input_buffer;
1324 1327
    }
1328
    init_get_bits(&s->gbc, buf, buf_size * 8);
1325 1329

  
1326 1330
    /* parse the syncinfo */
1327 1331
    *data_size = 0;

Also available in: Unified diff