Ticket #2664: 2664-v1.patch

File 2664-v1.patch, 3.4 KB (added by danielk, 17 years ago)

Preliminary stab at this problem.

  • libs/libmythtv/mpeg/mpegstreamdata.cpp

     
    692692        DONE_WITH_PES_PACKET(); // already parsed this table, toss it.
    693693    }
    694694
    695     HandleTables(tspacket->PID(), *psip);
     695    if (psip->VerifyPSIP(!_have_CRC_bug))
     696        HandleTables(tspacket->PID(), *psip);
     697
    696698    DONE_WITH_PES_PACKET();
    697699}
    698700#undef DONE_WITH_PES_PACKET
  • libs/libmythtv/mpeg/mpegtables.h

     
    359359    // only for real ATSC PSIP tables, not similar MPEG2 tables
    360360    void SetProtocolVersion(int ver) { pesdata()[8] = ver; }
    361361
     362    const bool VerifyPSIP(bool verify_crc) const;
     363
    362364    const QString toString(void) const;
    363365
    364366    static const uint PSIP_OFFSET = 8; // general PSIP header offset
  • libs/libmythtv/mpeg/mpegtables.cpp

     
    6666    return stream_id;
    6767}
    6868
     69const bool PSIPTable::VerifyPSIP(bool verify_crc) const
     70{
     71    if (verify_crc && (CalcCRC() != CRC()))
     72    {
     73        VERBOSE(VB_SIPARSER,
     74                QString("PSIPTable: Failed CRC check 0x%1 != 0x%2 "
     75                        "for StreamID = 0x%3")
     76                .arg(CRC(),0,16).arg(CalcCRC(),0,16).arg(StreamID(),0,16));
     77        return false;
     78    }
     79
     80    unsigned char *bufend = _fullbuffer + _allocSize;
     81
     82    if ((_pesdata + 2) >= bufend)
     83        return false; // can't query length
     84
     85    if (psipdata() >= bufend)
     86        return false; // data outside buffer
     87
     88    if (TableID::PAT == TableID())
     89    {
     90        uint pcnt = (SectionLength() - PSIP_OFFSET - 2) >> 2;
     91        return (psipdata() + (pcnt << 2) + 3 < bufend);
     92    }
     93
     94    if (TableID::PMT == TableID())
     95    {
     96        if (psipdata() + 3 >= bufend)
     97            return false; // can't query program info length
     98
     99        ProgramMapTable pmt(*this);
     100        if ((pmt.ProgramInfo() > bufend) ||
     101            (pmt.ProgramInfo() + pmt.ProgramInfoLength() > bufend))
     102        {
     103            return false;
     104        }
     105
     106        for (uint i = 0; i < pmt.StreamCount(); i++)
     107        {
     108            if ((pmt.StreamInfo(i) > bufend) ||
     109                (pmt.StreamInfo(i) + pmt.StreamInfoLength(i) > bufend))
     110            {
     111                return false;
     112            }
     113        }
     114    }
     115}
     116
    69117ProgramAssociationTable* ProgramAssociationTable::CreateBlank(bool small)
    70118{
    71119    (void) small; // currently always a small packet..
  • libs/libmythtv/mpeg/pespacket.h

     
    249249
    250250    unsigned char *_pesdata;    ///< Pointer to PES data in full buffer
    251251    unsigned char *_fullbuffer; ///< Pointer to allocated data
    252   private:
     252
    253253    uint _psiOffset;    ///< AFCOffset + StartOfFieldPointer
    254254    uint _ccLast;       ///< Continuity counter of last inserted TS Packet
    255255    uint _pesdataSize;  ///< Number of data bytes (TS header + PES data)