Ticket #3000: dvd-fix.patch

File dvd-fix.patch, 3.6 KB (added by skamithi, 17 years ago)
  • libs/libavformat/mpeg.c

     
    14401440{
    14411441    MpegDemuxContext *m = s->priv_data;
    14421442    int len, size, startcode, c, flags, header_len;
    1443     int64_t pts, dts;
    1444     int64_t last_sync= url_ftell(&s->pb);
     1443    int64_t pts, dts, last_pos;
    14451444
    1446  error_redo:
    1447         url_fseek(&s->pb, last_sync, SEEK_SET);
     1445    last_pos = -1;
    14481446 redo:
    14491447        /* next start code (should be immediately after) */
    14501448        m->header_state = 0xff;
    14511449        size = MAX_SYNC_SIZE;
    14521450        startcode = find_next_start_code(&s->pb, &size, &m->header_state);
    1453         last_sync = url_ftell(&s->pb);
    1454     //printf("startcode=%x pos=0x%"PRIx64"\n", startcode, url_ftell(&s->pb));
     1451    //printf("startcode=%x pos=0x%Lx\n", startcode, url_ftell(&s->pb));
    14551452    if (startcode < 0)
    14561453        return AVERROR_IO;
    14571454    if (startcode == PACK_START_CODE)
     
    14841481    /* stuffing */
    14851482    for(;;) {
    14861483        if (len < 1)
    1487             goto error_redo;
     1484            goto redo;
    14881485        c = get_byte(&s->pb);
    14891486        len--;
    14901487        /* XXX: for mpeg1, should test only bit 7 */
     
    14931490    }
    14941491    if ((c & 0xc0) == 0x40) {
    14951492        /* buffer scale & size */
     1493        if (len < 2)
     1494            goto redo;
    14961495        get_byte(&s->pb);
    14971496        c = get_byte(&s->pb);
    14981497        len -= 2;
    14991498    }
    1500     if ((c & 0xe0) == 0x20) {
     1499    if ((c & 0xf0) == 0x20) {
     1500        if (len < 4)
     1501            goto redo;
    15011502        dts = pts = get_pts(&s->pb, c);
    15021503        len -= 4;
    1503         if (c & 0x10){
    1504             dts = get_pts(&s->pb, -1);
    1505             len -= 5;
    1506         }
     1504    } else if ((c & 0xf0) == 0x30) {
     1505        if (len < 9)
     1506            goto redo;
     1507        pts = get_pts(&s->pb, c);
     1508        dts = get_pts(&s->pb, -1);
     1509        len -= 9;
    15071510    } else if ((c & 0xc0) == 0x80) {
    15081511        /* mpeg 2 PES */
    15091512#if 0 /* some streams have this field set for no apparent reason */
     
    15161519        header_len = get_byte(&s->pb);
    15171520        len -= 2;
    15181521        if (header_len > len)
    1519             goto error_redo;
    1520         len -= header_len;
    1521         if (flags & 0x80) {
     1522            goto redo;
     1523        if ((flags & 0xc0) == 0x80) {
    15221524            dts = pts = get_pts(&s->pb, -1);
     1525            if (header_len < 5)
     1526                goto redo;
    15231527            header_len -= 5;
    1524             if (flags & 0x40) {
    1525                 dts = get_pts(&s->pb, -1);
    1526                 header_len -= 5;
    1527             }
     1528            len -= 5;
     1529        } if ((flags & 0xc0) == 0xc0) {
     1530            pts = get_pts(&s->pb, -1);
     1531            dts = get_pts(&s->pb, -1);
     1532            if (header_len < 10)
     1533                goto redo;
     1534            header_len -= 10;
     1535            len -= 10;
    15281536        }
    1529         if(header_len < 0)
    1530             goto error_redo;
    1531         url_fskip(&s->pb, header_len);
     1537        len -= header_len;
     1538        while (header_len > 0) {
     1539            get_byte(&s->pb);
     1540            header_len--;
     1541        }
    15321542    }
    15331543    else if( c!= 0xf )
    15341544        goto redo;
    15351545
    15361546    if (startcode == PRIVATE_STREAM_1 && !m->psm_es_type[startcode & 0xff]) {
     1547        if (len < 1)
     1548            goto redo;
    15371549        startcode = get_byte(&s->pb);
    15381550        len--;
    15391551        if (startcode >= 0x80 && startcode <= 0xbf) {
    15401552            /* audio: skip header */
     1553            if (len < 3)
     1554                goto redo;
    15411555            get_byte(&s->pb);
    15421556            get_byte(&s->pb);
    15431557            get_byte(&s->pb);
    15441558            len -= 3;
    15451559        }
    15461560    }
    1547     if(len<0)
    1548         goto error_redo;
    15491561    if(dts != AV_NOPTS_VALUE && ppos && s->build_index){
    15501562        int i;
    15511563        for(i=0; i<s->nb_streams; i++){