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

Side by Side Diff: source/patched-ffmpeg-mt/libavformat/matroskadec.c

Issue 3384002: ffmpeg source update for sep 09 (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/ffmpeg/
Patch Set: Created 10 years, 3 months 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
OLDNEW
1 /* 1 /*
2 * Matroska file demuxer 2 * Matroska file demuxer
3 * Copyright (c) 2003-2008 The FFmpeg Project 3 * Copyright (c) 2003-2008 The FFmpeg Project
4 * 4 *
5 * This file is part of FFmpeg. 5 * This file is part of FFmpeg.
6 * 6 *
7 * FFmpeg is free software; you can redistribute it and/or 7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public 8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version. 10 * version 2.1 of the License, or (at your option) any later version.
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 * Read: an "EBML number", which is defined as a variable-length 535 * Read: an "EBML number", which is defined as a variable-length
536 * array of bytes. The first byte indicates the length by giving a 536 * array of bytes. The first byte indicates the length by giving a
537 * number of 0-bits followed by a one. The position of the first 537 * number of 0-bits followed by a one. The position of the first
538 * "one" bit inside the first byte indicates the length of this 538 * "one" bit inside the first byte indicates the length of this
539 * number. 539 * number.
540 * Returns: number of bytes read, < 0 on error 540 * Returns: number of bytes read, < 0 on error
541 */ 541 */
542 static int ebml_read_num(MatroskaDemuxContext *matroska, ByteIOContext *pb, 542 static int ebml_read_num(MatroskaDemuxContext *matroska, ByteIOContext *pb,
543 int max_size, uint64_t *number) 543 int max_size, uint64_t *number)
544 { 544 {
545 int len_mask = 0x80, read = 1, n = 1; 545 int read = 1, n = 1;
546 int64_t total = 0; 546 uint64_t total = 0;
547 547
548 /* The first byte tells us the length in bytes - get_byte() can normally 548 /* The first byte tells us the length in bytes - get_byte() can normally
549 * return 0, but since that's not a valid first ebmlID byte, we can 549 * return 0, but since that's not a valid first ebmlID byte, we can
550 * use it safely here to catch EOS. */ 550 * use it safely here to catch EOS. */
551 if (!(total = get_byte(pb))) { 551 if (!(total = get_byte(pb))) {
552 /* we might encounter EOS here */ 552 /* we might encounter EOS here */
553 if (!url_feof(pb)) { 553 if (!url_feof(pb)) {
554 int64_t pos = url_ftell(pb); 554 int64_t pos = url_ftell(pb);
555 av_log(matroska->ctx, AV_LOG_ERROR, 555 av_log(matroska->ctx, AV_LOG_ERROR,
556 "Read error at pos. %"PRIu64" (0x%"PRIx64")\n", 556 "Read error at pos. %"PRIu64" (0x%"PRIx64")\n",
557 pos, pos); 557 pos, pos);
558 } 558 }
559 return AVERROR(EIO); /* EOS or actual I/O error */ 559 return AVERROR(EIO); /* EOS or actual I/O error */
560 } 560 }
561 561
562 /* get the length of the EBML number */ 562 /* get the length of the EBML number */
563 while (read <= max_size && !(total & len_mask)) { 563 read = 8 - ff_log2_tab[total];
564 read++;
565 len_mask >>= 1;
566 }
567 if (read > max_size) { 564 if (read > max_size) {
568 int64_t pos = url_ftell(pb) - 1; 565 int64_t pos = url_ftell(pb) - 1;
569 av_log(matroska->ctx, AV_LOG_ERROR, 566 av_log(matroska->ctx, AV_LOG_ERROR,
570 "Invalid EBML number size tag 0x%02x at pos %"PRIu64" (0x%"PRIx64 ")\n", 567 "Invalid EBML number size tag 0x%02x at pos %"PRIu64" (0x%"PRIx64 ")\n",
571 (uint8_t) total, pos, pos); 568 (uint8_t) total, pos, pos);
572 return AVERROR_INVALIDDATA; 569 return AVERROR_INVALIDDATA;
573 } 570 }
574 571
575 /* read out length */ 572 /* read out length */
576 total &= ~len_mask; 573 total ^= 1 << ff_log2_tab[total];
577 while (n++ < read) 574 while (n++ < read)
578 total = (total << 8) | get_byte(pb); 575 total = (total << 8) | get_byte(pb);
579 576
580 *number = total; 577 *number = total;
581 578
582 return read; 579 return read;
583 } 580 }
584 581
582 /**
583 * Read a EBML length value.
584 * This needs special handling for the "unknown length" case which has multiple
585 * encodings.
586 */
587 static int ebml_read_length(MatroskaDemuxContext *matroska, ByteIOContext *pb,
588 uint64_t *number)
589 {
590 int res = ebml_read_num(matroska, pb, 8, number);
591 if (res > 0 && *number + 1 == 1ULL << (7 * res))
592 *number = 0xffffffffffffffULL;
593 return res;
594 }
595
585 /* 596 /*
586 * Read the next element as an unsigned int. 597 * Read the next element as an unsigned int.
587 * 0 is success, < 0 is failure. 598 * 0 is success, < 0 is failure.
588 */ 599 */
589 static int ebml_read_uint(ByteIOContext *pb, int size, uint64_t *num) 600 static int ebml_read_uint(ByteIOContext *pb, int size, uint64_t *num)
590 { 601 {
591 int n = 0; 602 int n = 0;
592 603
593 if (size < 1 || size > 8) 604 if (size > 8)
594 return AVERROR_INVALIDDATA; 605 return AVERROR_INVALIDDATA;
595 606
596 /* big-endian ordering; build up number */ 607 /* big-endian ordering; build up number */
597 *num = 0; 608 *num = 0;
598 while (n++ < size) 609 while (n++ < size)
599 *num = (*num << 8) | get_byte(pb); 610 *num = (*num << 8) | get_byte(pb);
600 611
601 return 0; 612 return 0;
602 } 613 }
603 614
604 /* 615 /*
605 * Read the next element as a float. 616 * Read the next element as a float.
606 * 0 is success, < 0 is failure. 617 * 0 is success, < 0 is failure.
607 */ 618 */
608 static int ebml_read_float(ByteIOContext *pb, int size, double *num) 619 static int ebml_read_float(ByteIOContext *pb, int size, double *num)
609 { 620 {
610 if (size == 4) { 621 if (size == 0) {
622 *num = 0;
623 } else if (size == 4) {
611 *num= av_int2flt(get_be32(pb)); 624 *num= av_int2flt(get_be32(pb));
612 } else if(size==8){ 625 } else if(size==8){
613 *num= av_int2dbl(get_be64(pb)); 626 *num= av_int2dbl(get_be64(pb));
614 } else 627 } else
615 return AVERROR_INVALIDDATA; 628 return AVERROR_INVALIDDATA;
616 629
617 return 0; 630 return 0;
618 } 631 }
619 632
620 /* 633 /*
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 if (syntax->list_elem_size) { 796 if (syntax->list_elem_size) {
784 EbmlList *list = data; 797 EbmlList *list = data;
785 list->elem = av_realloc(list->elem, (list->nb_elem+1)*syntax->list_elem_ size); 798 list->elem = av_realloc(list->elem, (list->nb_elem+1)*syntax->list_elem_ size);
786 data = (char*)list->elem + list->nb_elem*syntax->list_elem_size; 799 data = (char*)list->elem + list->nb_elem*syntax->list_elem_size;
787 memset(data, 0, syntax->list_elem_size); 800 memset(data, 0, syntax->list_elem_size);
788 list->nb_elem++; 801 list->nb_elem++;
789 } 802 }
790 803
791 if (syntax->type != EBML_PASS && syntax->type != EBML_STOP) { 804 if (syntax->type != EBML_PASS && syntax->type != EBML_STOP) {
792 matroska->current_id = 0; 805 matroska->current_id = 0;
793 if ((res = ebml_read_num(matroska, pb, 8, &length)) < 0) 806 if ((res = ebml_read_length(matroska, pb, &length)) < 0)
794 return res; 807 return res;
795 } 808 }
796 809
797 switch (syntax->type) { 810 switch (syntax->type) {
798 case EBML_UINT: res = ebml_read_uint (pb, length, data); break; 811 case EBML_UINT: res = ebml_read_uint (pb, length, data); break;
799 case EBML_FLOAT: res = ebml_read_float (pb, length, data); break; 812 case EBML_FLOAT: res = ebml_read_float (pb, length, data); break;
800 case EBML_STR: 813 case EBML_STR:
801 case EBML_UTF8: res = ebml_read_ascii (pb, length, data); break; 814 case EBML_UTF8: res = ebml_read_ascii (pb, length, data); break;
802 case EBML_BIN: res = ebml_read_binary(pb, length, data); break; 815 case EBML_BIN: res = ebml_read_binary(pb, length, data); break;
803 case EBML_NEST: if ((res=ebml_read_master(matroska, length)) < 0) 816 case EBML_NEST: if ((res=ebml_read_master(matroska, length)) < 0)
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 MatroskaTrack *track) 916 MatroskaTrack *track)
904 { 917 {
905 MatroskaTrackEncoding *encodings = track->encodings.elem; 918 MatroskaTrackEncoding *encodings = track->encodings.elem;
906 uint8_t* data = *buf; 919 uint8_t* data = *buf;
907 int isize = *buf_size; 920 int isize = *buf_size;
908 uint8_t* pkt_data = NULL; 921 uint8_t* pkt_data = NULL;
909 int pkt_size = isize; 922 int pkt_size = isize;
910 int result = 0; 923 int result = 0;
911 int olen; 924 int olen;
912 925
926 if (pkt_size >= 10000000)
927 return -1;
928
913 switch (encodings[0].compression.algo) { 929 switch (encodings[0].compression.algo) {
914 case MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP: 930 case MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP:
915 return encodings[0].compression.settings.size; 931 return encodings[0].compression.settings.size;
916 #if HAVE_LZO1X_999_COMPRESS 932 #if HAVE_LZO1X_999_COMPRESS
917 case MATROSKA_TRACK_ENCODING_COMP_LZO: 933 case MATROSKA_TRACK_ENCODING_COMP_LZO:
918 do { 934 do {
919 olen = pkt_size *= 3; 935 olen = pkt_size *= 3;
920 pkt_data = av_realloc(pkt_data, pkt_size+AV_LZO_OUTPUT_PADDING); 936 pkt_data = av_realloc(pkt_data, pkt_size+AV_LZO_OUTPUT_PADDING);
921 result = av_lzo1x_decode(pkt_data, &olen, data, &isize); 937 result = av_lzo1x_decode(pkt_data, &olen, data, &isize);
922 } while (result==AV_LZO_OUTPUT_FULL && pkt_size<10000000); 938 } while (result==AV_LZO_OUTPUT_FULL && pkt_size<10000000);
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 + a * (h*w / a - track->audio.pkt_cnt--), a); 1761 + a * (h*w / a - track->audio.pkt_cnt--), a);
1746 pkt->pos = pos; 1762 pkt->pos = pos;
1747 pkt->stream_index = st->index; 1763 pkt->stream_index = st->index;
1748 dynarray_add(&matroska->packets,&matroska->num_packets,pkt); 1764 dynarray_add(&matroska->packets,&matroska->num_packets,pkt);
1749 } 1765 }
1750 } else { 1766 } else {
1751 MatroskaTrackEncoding *encodings = track->encodings.elem; 1767 MatroskaTrackEncoding *encodings = track->encodings.elem;
1752 int offset = 0, pkt_size = lace_size[n]; 1768 int offset = 0, pkt_size = lace_size[n];
1753 uint8_t *pkt_data = data; 1769 uint8_t *pkt_data = data;
1754 1770
1755 if (lace_size[n] > size) { 1771 if (pkt_size > size) {
1756 av_log(matroska->ctx, AV_LOG_ERROR, "Invalid packet size\n") ; 1772 av_log(matroska->ctx, AV_LOG_ERROR, "Invalid packet size\n") ;
1757 break; 1773 break;
1758 } 1774 }
1759 1775
1760 if (encodings && encodings->scope & 1) { 1776 if (encodings && encodings->scope & 1) {
1761 offset = matroska_decode_buffer(&pkt_data,&pkt_size, track); 1777 offset = matroska_decode_buffer(&pkt_data,&pkt_size, track);
1762 if (offset < 0) 1778 if (offset < 0)
1763 continue; 1779 continue;
1764 } 1780 }
1765 1781
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1923 "matroska,webm", 1939 "matroska,webm",
1924 NULL_IF_CONFIG_SMALL("Matroska/WebM file format"), 1940 NULL_IF_CONFIG_SMALL("Matroska/WebM file format"),
1925 sizeof(MatroskaDemuxContext), 1941 sizeof(MatroskaDemuxContext),
1926 matroska_probe, 1942 matroska_probe,
1927 matroska_read_header, 1943 matroska_read_header,
1928 matroska_read_packet, 1944 matroska_read_packet,
1929 matroska_read_close, 1945 matroska_read_close,
1930 matroska_read_seek, 1946 matroska_read_seek,
1931 .metadata_conv = ff_mkv_metadata_conv, 1947 .metadata_conv = ff_mkv_metadata_conv,
1932 }; 1948 };
OLDNEW
« no previous file with comments | « source/patched-ffmpeg-mt/libavformat/m4vdec.c ('k') | source/patched-ffmpeg-mt/libavformat/metadata.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698