~ubuntu-branches/ubuntu/quantal/libav/quantal-security

« back to all changes in this revision

Viewing changes to libavcodec/ac3dec.c

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2013-11-09 10:49:20 UTC
  • mfrom: (1.2.18)
  • Revision ID: package-import@ubuntu.com-20131109104920-9drwimuneeio3f7y
Tags: 6:0.8.9-0ubuntu0.12.10.1
Update to 0.8.9 to fix multiple security issues (LP: #1249621)

Show diffs side-by-side

added added

removed removed

Lines of Context:
297
297
        return ff_eac3_parse_header(s);
298
298
    } else {
299
299
        av_log(s->avctx, AV_LOG_ERROR, "E-AC-3 support not compiled in\n");
300
 
        return -1;
 
300
        return AVERROR(ENOSYS);
301
301
    }
302
302
}
303
303
 
822
822
            if (start_subband >= end_subband) {
823
823
                av_log(s->avctx, AV_LOG_ERROR, "invalid spectral extension "
824
824
                       "range (%d >= %d)\n", start_subband, end_subband);
825
 
                return -1;
 
825
                return AVERROR_INVALIDDATA;
826
826
            }
827
827
            if (dst_start_freq >= src_start_freq) {
828
828
                av_log(s->avctx, AV_LOG_ERROR, "invalid spectral extension "
829
829
                       "copy start bin (%d >= %d)\n", dst_start_freq, src_start_freq);
830
 
                return -1;
 
830
                return AVERROR_INVALIDDATA;
831
831
            }
832
832
 
833
833
            s->spx_dst_start_freq = dst_start_freq;
904
904
 
905
905
            if (channel_mode < AC3_CHMODE_STEREO) {
906
906
                av_log(s->avctx, AV_LOG_ERROR, "coupling not allowed in mono or dual-mono\n");
907
 
                return -1;
 
907
                return AVERROR_INVALIDDATA;
908
908
            }
909
909
 
910
910
            /* check for enhanced coupling */
934
934
            if (cpl_start_subband >= cpl_end_subband) {
935
935
                av_log(s->avctx, AV_LOG_ERROR, "invalid coupling range (%d >= %d)\n",
936
936
                       cpl_start_subband, cpl_end_subband);
937
 
                return -1;
 
937
                return AVERROR_INVALIDDATA;
938
938
            }
939
939
            s->start_freq[CPL_CH] = cpl_start_subband * 12 + 37;
940
940
            s->end_freq[CPL_CH]   = cpl_end_subband   * 12 + 37;
956
956
        if (!blk) {
957
957
            av_log(s->avctx, AV_LOG_ERROR, "new coupling strategy must "
958
958
                   "be present in block 0\n");
959
 
            return -1;
 
959
            return AVERROR_INVALIDDATA;
960
960
        } else {
961
961
            s->cpl_in_use[blk] = s->cpl_in_use[blk-1];
962
962
        }
986
986
                } else if (!blk) {
987
987
                    av_log(s->avctx, AV_LOG_ERROR, "new coupling coordinates must "
988
988
                           "be present in block 0\n");
989
 
                    return -1;
 
989
                    return AVERROR_INVALIDDATA;
990
990
                }
991
991
            } else {
992
992
                /* channel not in coupling */
1041
1041
                int bandwidth_code = get_bits(gbc, 6);
1042
1042
                if (bandwidth_code > 60) {
1043
1043
                    av_log(s->avctx, AV_LOG_ERROR, "bandwidth code = %d > 60\n", bandwidth_code);
1044
 
                    return -1;
 
1044
                    return AVERROR_INVALIDDATA;
1045
1045
                }
1046
1046
                s->end_freq[ch] = bandwidth_code * 3 + 73;
1047
1047
            }
1064
1064
                                 s->num_exp_groups[ch], s->dexps[ch][0],
1065
1065
                                 &s->dexps[ch][s->start_freq[ch]+!!ch])) {
1066
1066
                av_log(s->avctx, AV_LOG_ERROR, "exponent out-of-range\n");
1067
 
                return -1;
 
1067
                return AVERROR_INVALIDDATA;
1068
1068
            }
1069
1069
            if (ch != CPL_CH && ch != s->lfe_ch)
1070
1070
                skip_bits(gbc, 2); /* skip gainrng */
1084
1084
        } else if (!blk) {
1085
1085
            av_log(s->avctx, AV_LOG_ERROR, "new bit allocation info must "
1086
1086
                   "be present in block 0\n");
1087
 
            return -1;
 
1087
            return AVERROR_INVALIDDATA;
1088
1088
        }
1089
1089
    }
1090
1090
 
1115
1115
            }
1116
1116
        } else if (!s->eac3 && !blk) {
1117
1117
            av_log(s->avctx, AV_LOG_ERROR, "new snr offsets must be present in block 0\n");
1118
 
            return -1;
 
1118
            return AVERROR_INVALIDDATA;
1119
1119
        }
1120
1120
    }
1121
1121
 
1154
1154
        } else if (!s->eac3 && !blk) {
1155
1155
            av_log(s->avctx, AV_LOG_ERROR, "new coupling leak info must "
1156
1156
                   "be present in block 0\n");
1157
 
            return -1;
 
1157
            return AVERROR_INVALIDDATA;
1158
1158
        }
1159
1159
        s->first_cpl_leak = 0;
1160
1160
    }
1166
1166
            s->dba_mode[ch] = get_bits(gbc, 2);
1167
1167
            if (s->dba_mode[ch] == DBA_RESERVED) {
1168
1168
                av_log(s->avctx, AV_LOG_ERROR, "delta bit allocation strategy reserved\n");
1169
 
                return -1;
 
1169
                return AVERROR_INVALIDDATA;
1170
1170
            }
1171
1171
            bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2);
1172
1172
        }
1207
1207
                                           s->dba_offsets[ch], s->dba_lengths[ch],
1208
1208
                                           s->dba_values[ch],  s->mask[ch])) {
1209
1209
                av_log(s->avctx, AV_LOG_ERROR, "error in bit allocation\n");
1210
 
                return -1;
 
1210
                return AVERROR_INVALIDDATA;
1211
1211
            }
1212
1212
        }
1213
1213
        if (bit_alloc_stages[ch] > 0) {
1328
1328
        switch (err) {
1329
1329
        case AAC_AC3_PARSE_ERROR_SYNC:
1330
1330
            av_log(avctx, AV_LOG_ERROR, "frame sync error\n");
1331
 
            return -1;
 
1331
            return AVERROR_INVALIDDATA;
1332
1332
        case AAC_AC3_PARSE_ERROR_BSID:
1333
1333
            av_log(avctx, AV_LOG_ERROR, "invalid bitstream id\n");
1334
1334
            break;
1342
1342
            /* skip frame if CRC is ok. otherwise use error concealment. */
1343
1343
            /* TODO: add support for substreams and dependent frames */
1344
1344
            if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT || s->substreamid) {
1345
 
                av_log(avctx, AV_LOG_ERROR, "unsupported frame type : "
 
1345
                av_log(avctx, AV_LOG_WARNING, "unsupported frame type : "
1346
1346
                       "skipping frame\n");
1347
1347
                *got_frame_ptr = 0;
1348
 
                return s->frame_size;
 
1348
                return buf_size;
1349
1349
            } else {
1350
1350
                av_log(avctx, AV_LOG_ERROR, "invalid frame type\n");
1351
1351
            }
1352
1352
            break;
1353
 
        default:
1354
 
            av_log(avctx, AV_LOG_ERROR, "invalid header\n");
 
1353
        case AAC_AC3_PARSE_ERROR_CRC:
 
1354
        case AAC_AC3_PARSE_ERROR_CHANNEL_CFG:
1355
1355
            break;
 
1356
        default: // Normal AVERROR do not try to recover.
 
1357
            *got_frame_ptr = 0;
 
1358
            return err;
1356
1359
        }
1357
1360
    } else {
1358
1361
        /* check that reported frame size fits in input buffer */
1373
1376
    if (!err) {
1374
1377
        avctx->sample_rate = s->sample_rate;
1375
1378
        avctx->bit_rate    = s->bit_rate;
 
1379
    }
1376
1380
 
1377
 
        /* channel config */
 
1381
    /* channel config */
 
1382
    if (!err || (s->channels && s->out_channels != s->channels)) {
1378
1383
        s->out_channels = s->channels;
1379
1384
        s->output_mode  = s->channel_mode;
1380
1385
        if (s->lfe_on)
1393
1398
                s->fbw_channels == s->out_channels)) {
1394
1399
            set_downmix_coeffs(s);
1395
1400
        }
1396
 
    } else if (!s->out_channels) {
1397
 
        s->out_channels = avctx->channels;
1398
 
        if (s->out_channels < s->channels)
1399
 
            s->output_mode  = s->out_channels == 1 ? AC3_CHMODE_MONO : AC3_CHMODE_STEREO;
 
1401
    } else if (!s->channels) {
 
1402
        av_log(avctx, AV_LOG_ERROR, "unable to determine channel mode\n");
 
1403
        return AVERROR_INVALIDDATA;
1400
1404
    }
 
1405
    avctx->channels = s->out_channels;
 
1406
 
1401
1407
    /* set audio service type based on bitstream mode for AC-3 */
1402
1408
    avctx->audio_service_type = s->bitstream_mode;
1403
1409
    if (s->bitstream_mode == 0x7 && s->channels > 1)
1404
1410
        avctx->audio_service_type = AV_AUDIO_SERVICE_TYPE_KARAOKE;
1405
1411
 
1406
1412
    /* get output buffer */
1407
 
    avctx->channels = s->out_channels;
1408
1413
    s->frame.nb_samples = s->num_blocks * 256;
1409
1414
    if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) {
1410
1415
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");