Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: source/patched-ffmpeg/libavcodec/vorbisdec.c

Issue 8414025: An additional defense in the Vorbis codec. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/ffmpeg/
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « patches/to_upstream/49_vorbis_buffer_defense.patch ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /** 1 /**
2 * @file 2 * @file
3 * Vorbis I decoder 3 * Vorbis I decoder
4 * @author Denes Balatoni ( dbalatoni programozo hu ) 4 * @author Denes Balatoni ( dbalatoni programozo hu )
5 * 5 *
6 * This file is part of FFmpeg. 6 * This file is part of FFmpeg.
7 * 7 *
8 * FFmpeg is free software; you can redistribute it and/or 8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public 9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 1253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 } 1264 }
1265 1265
1266 // Read and decode residue 1266 // Read and decode residue
1267 1267
1268 static av_always_inline int vorbis_residue_decode_internal(vorbis_context *vc, 1268 static av_always_inline int vorbis_residue_decode_internal(vorbis_context *vc,
1269 vorbis_residue *vr, 1269 vorbis_residue *vr,
1270 unsigned ch, 1270 unsigned ch,
1271 uint8_t *do_not_decod e, 1271 uint8_t *do_not_decod e,
1272 float *vec, 1272 float *vec,
1273 unsigned vlen, 1273 unsigned vlen,
1274 unsigned ch_left,
1274 int vr_type) 1275 int vr_type)
1275 { 1276 {
1276 GetBitContext *gb = &vc->gb; 1277 GetBitContext *gb = &vc->gb;
1277 unsigned c_p_c = vc->codebooks[vr->classbook].dimensions; 1278 unsigned c_p_c = vc->codebooks[vr->classbook].dimensions;
1278 unsigned ptns_to_read = vr->ptns_to_read; 1279 unsigned ptns_to_read = vr->ptns_to_read;
1279 uint8_t *classifs = vr->classifs; 1280 uint8_t *classifs = vr->classifs;
1280 unsigned pass, ch_used, i, j, k, l; 1281 unsigned pass, ch_used, i, j, k, l;
1282 unsigned max_output = (ch - 1) * vlen;
1281 1283
1282 if (vr_type == 2) { 1284 if (vr_type == 2) {
1283 for (j = 1; j < ch; ++j) 1285 for (j = 1; j < ch; ++j)
1284 do_not_decode[0] &= do_not_decode[j]; // FIXME - clobbering input 1286 do_not_decode[0] &= do_not_decode[j]; // FIXME - clobbering input
1285 if (do_not_decode[0]) 1287 if (do_not_decode[0])
1286 return 0; 1288 return 0;
1287 ch_used = 1; 1289 ch_used = 1;
1290 max_output += vr->end / ch;
1288 } else { 1291 } else {
1289 ch_used = ch; 1292 ch_used = ch;
1293 max_output += vr->end;
1294 }
1295
1296 if (max_output > ch_left * vlen) {
1297 av_log(vc->avccontext, AV_LOG_ERROR, "Insufficient output buffer\n");
1298 return -1;
1290 } 1299 }
1291 1300
1292 av_dlog(NULL, " residue type 0/1/2 decode begin, ch: %d cpc %d \n", ch, c_ p_c); 1301 av_dlog(NULL, " residue type 0/1/2 decode begin, ch: %d cpc %d \n", ch, c_ p_c);
1293 1302
1294 for (pass = 0; pass <= vr->maxpass; ++pass) { // FIXME OPTIMIZE? 1303 for (pass = 0; pass <= vr->maxpass; ++pass) { // FIXME OPTIMIZE?
1295 uint16_t voffset, partition_count, j_times_ptns_to_read; 1304 uint16_t voffset, partition_count, j_times_ptns_to_read;
1296 1305
1297 voffset = vr->begin; 1306 voffset = vr->begin;
1298 for(partition_count=0;partition_count<ptns_to_read && !(gb->buffer_exhau sted && gb->index > gb->size_in_bits);) { // SPEC error 1307 for(partition_count=0;partition_count<ptns_to_read && !(gb->buffer_exhau sted && gb->index > gb->size_in_bits);) { // SPEC error
1299 if (!pass) { 1308 if (!pass) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 voffset += vr->partition_size; 1415 voffset += vr->partition_size;
1407 } 1416 }
1408 } 1417 }
1409 } 1418 }
1410 return 0; 1419 return 0;
1411 } 1420 }
1412 1421
1413 static inline int vorbis_residue_decode(vorbis_context *vc, vorbis_residue *vr, 1422 static inline int vorbis_residue_decode(vorbis_context *vc, vorbis_residue *vr,
1414 unsigned ch, 1423 unsigned ch,
1415 uint8_t *do_not_decode, 1424 uint8_t *do_not_decode,
1416 float *vec, unsigned vlen) 1425 float *vec, unsigned vlen,
1426 unsigned ch_left)
1417 { 1427 {
1418 if (vr->type == 2) 1428 if (vr->type == 2)
1419 return vorbis_residue_decode_internal(vc, vr, ch, do_not_decode, vec, vl en, 2); 1429 return vorbis_residue_decode_internal(vc, vr, ch, do_not_decode, vec, vl en, ch_left, 2);
1420 else if (vr->type == 1) 1430 else if (vr->type == 1)
1421 return vorbis_residue_decode_internal(vc, vr, ch, do_not_decode, vec, vl en, 1); 1431 return vorbis_residue_decode_internal(vc, vr, ch, do_not_decode, vec, vl en, ch_left, 1);
1422 else if (vr->type == 0) 1432 else if (vr->type == 0)
1423 return vorbis_residue_decode_internal(vc, vr, ch, do_not_decode, vec, vl en, 0); 1433 return vorbis_residue_decode_internal(vc, vr, ch, do_not_decode, vec, vl en, ch_left, 0);
1424 else { 1434 else {
1425 av_log(vc->avccontext, AV_LOG_ERROR, " Invalid residue type while residu e decode?! \n"); 1435 av_log(vc->avccontext, AV_LOG_ERROR, " Invalid residue type while residu e decode?! \n");
1426 return -1; 1436 return -1;
1427 } 1437 }
1428 } 1438 }
1429 1439
1430 void vorbis_inverse_coupling(float *mag, float *ang, int blocksize) 1440 void vorbis_inverse_coupling(float *mag, float *ang, int blocksize)
1431 { 1441 {
1432 int i; 1442 int i;
1433 for (i = 0; i < blocksize; i++) { 1443 for (i = 0; i < blocksize; i++) {
(...skipping 27 matching lines...) Expand all
1461 unsigned mode_number, blockflag, blocksize; 1471 unsigned mode_number, blockflag, blocksize;
1462 int i, j; 1472 int i, j;
1463 uint8_t no_residue[255]; 1473 uint8_t no_residue[255];
1464 uint8_t do_not_decode[255]; 1474 uint8_t do_not_decode[255];
1465 vorbis_mapping *mapping; 1475 vorbis_mapping *mapping;
1466 float *ch_res_ptr = vc->channel_residues; 1476 float *ch_res_ptr = vc->channel_residues;
1467 float *ch_floor_ptr = vc->channel_floors; 1477 float *ch_floor_ptr = vc->channel_floors;
1468 uint8_t res_chan[255]; 1478 uint8_t res_chan[255];
1469 unsigned res_num = 0; 1479 unsigned res_num = 0;
1470 int retlen = 0; 1480 int retlen = 0;
1471 int ch_left = vc->audio_channels; 1481 unsigned ch_left = vc->audio_channels;
1482 unsigned vlen;
1472 1483
1473 if (get_bits1(gb)) { 1484 if (get_bits1(gb)) {
1474 av_log(vc->avccontext, AV_LOG_ERROR, "Not a Vorbis I audio packet.\n"); 1485 av_log(vc->avccontext, AV_LOG_ERROR, "Not a Vorbis I audio packet.\n");
1475 return -1; // packet type not audio 1486 return -1; // packet type not audio
1476 } 1487 }
1477 1488
1478 if (vc->mode_count == 1) { 1489 if (vc->mode_count == 1) {
1479 mode_number = 0; 1490 mode_number = 0;
1480 } else { 1491 } else {
1481 GET_VALIDATED_INDEX(mode_number, ilog(vc->mode_count-1), vc->mode_count) 1492 GET_VALIDATED_INDEX(mode_number, ilog(vc->mode_count-1), vc->mode_count)
1482 } 1493 }
1483 vc->mode_number = mode_number; 1494 vc->mode_number = mode_number;
1484 mapping = &vc->mappings[vc->modes[mode_number].mapping]; 1495 mapping = &vc->mappings[vc->modes[mode_number].mapping];
1485 1496
1486 av_dlog(NULL, " Mode number: %u , mapping: %d , blocktype %d\n", mode_number , 1497 av_dlog(NULL, " Mode number: %u , mapping: %d , blocktype %d\n", mode_number ,
1487 vc->modes[mode_number].mapping, vc->modes[mode_number].blockflag); 1498 vc->modes[mode_number].mapping, vc->modes[mode_number].blockflag);
1488 1499
1489 blockflag = vc->modes[mode_number].blockflag; 1500 blockflag = vc->modes[mode_number].blockflag;
1490 blocksize = vc->blocksize[blockflag]; 1501 blocksize = vc->blocksize[blockflag];
1502 vlen = blocksize / 2;
1491 if (blockflag) 1503 if (blockflag)
1492 skip_bits(gb, 2); // previous_window, next_window 1504 skip_bits(gb, 2); // previous_window, next_window
1493 1505
1494 memset(ch_res_ptr, 0, sizeof(float) * vc->audio_channels * blocksize / 2); //FIXME can this be removed ? 1506 memset(ch_res_ptr, 0, sizeof(float) * vc->audio_channels * vlen); //FIXME can this be removed ?
1495 memset(ch_floor_ptr, 0, sizeof(float) * vc->audio_channels * blocksize / 2); //FIXME can this be removed ? 1507 memset(ch_floor_ptr, 0, sizeof(float) * vc->audio_channels * vlen); //FIXME can this be removed ?
1496 1508
1497 // Decode floor 1509 // Decode floor
1498 1510
1499 for (i = 0; i < vc->audio_channels; ++i) { 1511 for (i = 0; i < vc->audio_channels; ++i) {
1500 vorbis_floor *floor; 1512 vorbis_floor *floor;
1501 int ret; 1513 int ret;
1502 if (mapping->submaps > 1) { 1514 if (mapping->submaps > 1) {
1503 floor = &vc->floors[mapping->submap_floor[mapping->mux[i]]]; 1515 floor = &vc->floors[mapping->submap_floor[mapping->mux[i]]];
1504 } else { 1516 } else {
1505 floor = &vc->floors[mapping->submap_floor[0]]; 1517 floor = &vc->floors[mapping->submap_floor[0]];
1506 } 1518 }
1507 1519
1508 ret = floor->decode(vc, &floor->data, ch_floor_ptr); 1520 ret = floor->decode(vc, &floor->data, ch_floor_ptr);
1509 1521
1510 if (ret < 0) { 1522 if (ret < 0) {
1511 av_log(vc->avccontext, AV_LOG_ERROR, "Invalid codebook in vorbis_flo or_decode.\n"); 1523 av_log(vc->avccontext, AV_LOG_ERROR, "Invalid codebook in vorbis_flo or_decode.\n");
1512 return -1; 1524 return -1;
1513 } 1525 }
1514 no_residue[i] = ret; 1526 no_residue[i] = ret;
1515 ch_floor_ptr += blocksize / 2; 1527 ch_floor_ptr += vlen;
1516 } 1528 }
1517 1529
1518 // Nonzero vector propagate 1530 // Nonzero vector propagate
1519 1531
1520 for (i = mapping->coupling_steps - 1; i >= 0; --i) { 1532 for (i = mapping->coupling_steps - 1; i >= 0; --i) {
1521 if (!(no_residue[mapping->magnitude[i]] & no_residue[mapping->angle[i]]) ) { 1533 if (!(no_residue[mapping->magnitude[i]] & no_residue[mapping->angle[i]]) ) {
1522 no_residue[mapping->magnitude[i]] = 0; 1534 no_residue[mapping->magnitude[i]] = 0;
1523 no_residue[mapping->angle[i]] = 0; 1535 no_residue[mapping->angle[i]] = 0;
1524 } 1536 }
1525 } 1537 }
1526 1538
1527 // Decode residue 1539 // Decode residue
1528 1540
1529 for (i = 0; i < mapping->submaps; ++i) { 1541 for (i = 0; i < mapping->submaps; ++i) {
1530 vorbis_residue *residue; 1542 vorbis_residue *residue;
1531 unsigned ch = 0; 1543 unsigned ch = 0;
1544 int ret;
1532 1545
1533 for (j = 0; j < vc->audio_channels; ++j) { 1546 for (j = 0; j < vc->audio_channels; ++j) {
1534 if ((mapping->submaps == 1) || (i == mapping->mux[j])) { 1547 if ((mapping->submaps == 1) || (i == mapping->mux[j])) {
1535 res_chan[j] = res_num; 1548 res_chan[j] = res_num;
1536 if (no_residue[j]) { 1549 if (no_residue[j]) {
1537 do_not_decode[ch] = 1; 1550 do_not_decode[ch] = 1;
1538 } else { 1551 } else {
1539 do_not_decode[ch] = 0; 1552 do_not_decode[ch] = 0;
1540 } 1553 }
1541 ++ch; 1554 ++ch;
1542 ++res_num; 1555 ++res_num;
1543 } 1556 }
1544 } 1557 }
1545 residue = &vc->residues[mapping->submap_residue[i]]; 1558 residue = &vc->residues[mapping->submap_residue[i]];
1546 if (ch_left < ch) { 1559 if (ch_left < ch) {
1547 av_log(vc->avccontext, AV_LOG_ERROR, "Too many channels in vorbis_fl oor_decode.\n"); 1560 av_log(vc->avccontext, AV_LOG_ERROR, "Too many channels in vorbis_fl oor_decode.\n");
1548 return -1; 1561 return -1;
1549 } 1562 }
1550 vorbis_residue_decode(vc, residue, ch, do_not_decode, ch_res_ptr, blocks ize/2); 1563 ret = vorbis_residue_decode(vc, residue, ch, do_not_decode, ch_res_ptr, vlen, ch_left);
1564 if (ret < 0)
1565 return ret;
1551 1566
1552 ch_res_ptr += ch * blocksize / 2; 1567 ch_res_ptr += ch * vlen;
1553 ch_left -= ch; 1568 ch_left -= ch;
1554 } 1569 }
1555 1570
1556 // Inverse coupling 1571 // Inverse coupling
1557 1572
1558 for (i = mapping->coupling_steps - 1; i >= 0; --i) { //warning: i has to be signed 1573 for (i = mapping->coupling_steps - 1; i >= 0; --i) { //warning: i has to be signed
1559 float *mag, *ang; 1574 float *mag, *ang;
1560 1575
1561 mag = vc->channel_residues+res_chan[mapping->magnitude[i]] * blocksize / 2; 1576 mag = vc->channel_residues+res_chan[mapping->magnitude[i]] * blocksize / 2;
1562 ang = vc->channel_residues+res_chan[mapping->angle[i]] * blocksize / 2; 1577 ang = vc->channel_residues+res_chan[mapping->angle[i]] * blocksize / 2;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1680 NULL, 1695 NULL,
1681 vorbis_decode_close, 1696 vorbis_decode_close,
1682 vorbis_decode_frame, 1697 vorbis_decode_frame,
1683 .long_name = NULL_IF_CONFIG_SMALL("Vorbis"), 1698 .long_name = NULL_IF_CONFIG_SMALL("Vorbis"),
1684 .channel_layouts = ff_vorbis_channel_layouts, 1699 .channel_layouts = ff_vorbis_channel_layouts,
1685 .sample_fmts = (const enum AVSampleFormat[]) { 1700 .sample_fmts = (const enum AVSampleFormat[]) {
1686 AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE 1701 AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE
1687 }, 1702 },
1688 }; 1703 };
1689 1704
OLDNEW
« no previous file with comments | « patches/to_upstream/49_vorbis_buffer_defense.patch ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698