Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More robust parsing for ATSC PSIP tables (proposal) #624

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

linuxdude42
Copy link
Contributor

This is my current set of proposed changes to validate all ATSC PSIP tables instead of blindly trusting their data. The table parsing functions have been enhanced to do the following:

  1. Calculate the maximum possible table size given the size of the received PES packet.
  2. Validate the stated table size against the maximum possible size.
  3. Save the validated table size for all subsequent table size references.
  4. While processing the tables, check every variable length field to ensure it doesn't run past the end of the received data.

I have also added a number of compile time parsing tests for the ATSC parsers.

The following pieces of code will be removed before commit:

  1. All old parsing functions.
  2. The constructor changes to call old/new parser functions.
  3. All timing related tests. These are only for development to validate that the new parsers are faster than the old.

@linuxdude42 linuxdude42 linked an issue Aug 17, 2022 that may be closed by this pull request
@linuxdude42 linuxdude42 self-assigned this Aug 17, 2022
@linuxdude42 linuxdude42 requested a review from kmdewaal August 17, 2022 15:37
When parsing any of the variable length portions of any of the ATSC
PSIP tables, ensure that the parsing never reads past the end of the
packet.  Knowing the number of entries in the table up front also
allows for preallocating all the space needed for the m_ptr array up
front, instead of std::vector making multiple allocation requests as
the vector size grows.  Add error counters that are printed when a
recording is stopped.
1) SpliceInformationTable::Parse handing for a splice_insert (that
isn't a cancel) needs to set m_epilog.

2) Return proper length from SpliceTimeView::size.

3) SpliceInsertView::IsSpliceImmediate needs to check the proper bit.

4) Add accessor functions to SpliceInsertView to retrieve component information.

5) SpliceInformationTable::SpliceDescriptorsLength doesn't need an argument.

6) SpliceInformationTable::SpliceDescriptors should return nullptr if
m_epilog is set but the descriptor count is zero.

7) Add test cases.
1) Correct the values pushed into slice (m_ptrs1) array.

2) Update the working pointer after each entry in the splice table is
processed, so the next slice is processed. (Old code processed the
first slice n times.)

3) Add test cases.
When parsing any of the variable length portions of any of the SCTE
Splice, ensure that the parsing never reads past the end of the
packet.  Knowing the number of entries in the table up front also
allows for preallocating all the space needed up front, instead of
std::vector making multiple allocation requests as the vector size
grows.
When parsing any of the variable length portions of any of the PMT,
ensure that the parsing never reads past the end of the packet.
Knowing the number of entries in the table up front also allows for
preallocating all the space needed up front, instead of std::vector
making multiple allocation requests as the vector size grows.

The PMT parse checks have to be conditional because MythTV generates
blank PMT packets and then fills them in with data.
When parsing any of the variable length portions of any of these
tables, ensure that the parsing never reads past the end of the
packet.  Knowing the number of entries in the table up front also
allows for preallocating all the space needed up front, instead of
std::vector making multiple allocation requests as the vector size
grows.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PSIP table parsing should be more robust
1 participant