Skip to content

Comments

Adding Additional Tests for SCTE-35 Parser for robustness#10

Merged
theRealRobG merged 2 commits intotheRealRobG:mainfrom
yewonjohn:VPTAPPLE-2249
Jul 11, 2025
Merged

Adding Additional Tests for SCTE-35 Parser for robustness#10
theRealRobG merged 2 commits intotheRealRobG:mainfrom
yewonjohn:VPTAPPLE-2249

Conversation

@yewonjohn
Copy link

@yewonjohn yewonjohn commented Jul 10, 2025

Description

This PR adds and documents additional tests targeting SCTE-35 parser robustness, focusing on error handling for malformed, truncated, or otherwise invalid input.

Requires @theRealRobG review & approval to validate the hexes and to see if the errors thrown in each test is expected.


1. test_invalidHexInISANShouldThrow

Intent:
Ensure the parser rejects hex strings with non-hexadecimal characters (malformed input).

Description:
Tests that passing a hex string with an invalid character ('Z') in the ISAN field results in a thrown error, confirming the parser correctly validates input format.

Hex Construction:
The test hex string is a valid SCTE-35 message except for a single non-hex character (Z) embedded in the ISAN field. This simulates a corrupt or malformed input.

Error Thrown:

invalidInputString("FC302000000000000000FFF00506FE...0000000Z")

2. test_randomNoiseInput_shouldNotCrash

Intent:
Ensure parser robustness against random or malformed input.

Description:
Fuzzes the parser with 100 random base64-encoded data blobs of varying lengths and asserts that the parser never crashes (it may throw errors, which is acceptable).

Hex Construction:
The test data is not a crafted SCTE-35 hex string at all. Instead, it generates random bytes, encodes them as base64, and attempts to parse them as if they were a valid SCTE-35 message.

Error Thrown:
No crashes; errors may be thrown but are expected.


3. test_descriptorLengthTooShort_throwsError

Intent:
Detect under-declared descriptor lengths.

Description:
Checks that if the descriptor length field declares more data than is actually present for the descriptor, the parser throws an error (truncated or incomplete descriptor).

Hex Construction:
The descriptor length field (immediately after the descriptor tag) is set to a value (0A, or 10 bytes) larger than the number of bytes actually present in the descriptor payload (only 6 bytes provided after the length field). The hex string is cut short to simulate truncation.

Error Thrown:

SCTE35ParserError(error: SCTE35Parser.ParserError.unexpectedEndOfData(
  SCTE35Parser.UnexpectedEndOfDataErrorInfo(
    expectedMinimumBitsLeft: 320,
    actualBitsLeft: 128,
    description: "SpliceInfoSection; section_length defined as 40"
  )
), underlyingError: nil)

4. test_descriptorLengthTooLong_throwsError

Intent:
Detect over-declared descriptor loop lengths (buffer overrun).

Description:
Verifies that if the descriptor loop length field declares more bytes than are available, the parser throws an error (unexpected end of data or overrun).

Hex Construction:
The descriptor loop length field (in the SCTE-35 section header) is set to a value (20, or 32 bytes) that is larger than the actual number of bytes available for all descriptors combined. The message is not padded to match, so the parser will run out of data when trying to read descriptors.

Error Thrown:

SCTE35ParserError(error: SCTE35Parser.ParserError.unexpectedEndOfData(
  SCTE35Parser.UnexpectedEndOfDataErrorInfo(
    expectedMinimumBitsLeft: 69632,
    actualBitsLeft: 184,
    description: "SpliceDescriptor; reading loop"
  )
), underlyingError: Optional(
  SCTE35Parser.ParserError.unexpectedSpliceCommandLength(
    SCTE35Parser.UnexpectedSpliceCommandLengthErrorInfo(
      declaredSpliceCommandLengthInBits: 896,
      actualSpliceCommandLengthInBits: 40,
      spliceCommandType: SCTE35Parser.SpliceCommandType.spliceInsert
    )
  )
))

5. test_unknownCommandAndDescriptorIDs

Intent:
Ensure errors are thrown for unknown/reserved command, descriptor, and type IDs.

Description:
Tests that the parser throws errors when encountering:

  • An unknown splice command type,
  • An unknown splice descriptor tag,
  • An unknown segmentation type ID,
    verifying that reserved or invalid identifier values are flagged as errors.

Hex Construction:

  • Unknown splice command type: The splice_command_type byte is set to FF (an undefined value).
  • Unknown descriptor tag: The descriptor tag byte is set to FF (not a defined descriptor type).
  • Unknown segmentation type ID: The segmentation type ID byte (part of a segmentation descriptor) is set to FF (not a valid type).

Errors Thrown:

SCTE35ParserError(error: SCTE35Parser.ParserError.unexpectedEndOfData(
  SCTE35Parser.UnexpectedEndOfDataErrorInfo(
    expectedMinimumBitsLeft: 2040,
    actualBitsLeft: 408,
    description: "SpliceInfoSection; section_length defined as 255"
  )
), underlyingError: nil)

SCTE35ParserError(error: SCTE35Parser.ParserError.unexpectedEndOfData(
  SCTE35Parser.UnexpectedEndOfDataErrorInfo(
    expectedMinimumBitsLeft: 320,
    actualBitsLeft: 304,
    description: "SpliceInfoSection; section_length defined as 40"
  )
), underlyingError: nil)

SCTE35ParserError(error: SCTE35Parser.ParserError.unexpectedEndOfData(
  SCTE35Parser.UnexpectedEndOfDataErrorInfo(
    expectedMinimumBitsLeft: 320,
    actualBitsLeft: 272,
    description: "SpliceInfoSection; section_length defined as 40"
  )
), underlyingError: nil)

@yewonjohn yewonjohn changed the title Add additional tests Adding Additional SCTE-35 Parser for robustness Jul 10, 2025
@yewonjohn yewonjohn changed the title Adding Additional SCTE-35 Parser for robustness Adding Additional Tests for SCTE-35 Parser for robustness Jul 10, 2025
Copy link
Owner

@theRealRobG theRealRobG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for the addition!

I left 2 comments; the first I already indicated is not anything to act on (I'm fine not validating the error case thrown), but I think a comment should be added for the fuzz test against fatal crashes... What do you think?

@theRealRobG theRealRobG merged commit 3553cfd into theRealRobG:main Jul 11, 2025
1 check passed
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.

3 participants