Ticket #1790: pes_assembly_robustness.diff

File pes_assembly_robustness.diff, 1.5 KB (added by Janne <janne-mythtv@…>, 14 years ago)

adds checks in AssemblePSIP to avoid processing invalid data

  • libs/libmythtv/mpeg/mpegstreamdata.cpp

    old new PSIPTable* MPEGStreamData::AssemblePSIP( 
    196196    PESPacket* partial = GetPartialPES(tspacket->PID());
    197197    if (partial && partial->AddTSPacket(tspacket))
    198198    {
     199        // discard broken packets
     200        if (!partial->IsGood())
     201        {
     202            VERBOSE(VB_IMPORTANT, "Discard broken pes packet!");
     203            ClearPartialPES(tspacket->PID());
     204            return NULL;
     205        }
     206
    199207        PSIPTable* psip = new PSIPTable(*partial);
    200208
    201209        // Advance to the next packet
    202210        // pesdata starts only at PSIOffset()+1
    203211        uint packetStart = partial->PSIOffset() + 1 + psip->SectionLength();
    204         if (packetStart < partial->TSSizeInBuffer())
     212        if (packetStart < partial->TSSizeInBuffer() &&
     213            packetStart+TSPacket::SIZE > partial->TSSizeInBuffer())
    205214        {
    206215            if (partial->pesdata()[psip->SectionLength()] != 0xff)
    207216            {
    PSIPTable* MPEGStreamData::AssemblePSIP( 
    223232                return psip;
    224233            }
    225234        }
     235        else
     236        {
     237            VERBOSE(VB_IMPORTANT, "Discard suspicious pes packet!");
     238            ClearPartialPES(tspacket->PID());
     239            return NULL;
     240        }
    226241
    227242        moreTablePackets = false;
    228243        DeletePartialPES(tspacket->PID());