diff --git a/Tests/SCTE35ParserTests/SCTE35ParserTests.swift b/Tests/SCTE35ParserTests/SCTE35ParserTests.swift index 3c9e7b5..a3d39ef 100644 --- a/Tests/SCTE35ParserTests/SCTE35ParserTests.swift +++ b/Tests/SCTE35ParserTests/SCTE35ParserTests.swift @@ -1402,4 +1402,53 @@ final class SCTE35ParserTests: XCTestCase { ) try XCTAssertEqual(expectedSpliceInfoSection, SpliceInfoSection(base64String)) } + + // MARK: - Input Validation + + /// Test: ISAN/EIDR UPID with non-hex character to target force-unwrap + func test_invalidHexInISANShouldThrow() { + let badISANHex = "FC302000000000000000FFF00506FE00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000Z" + XCTAssertThrowsError(try SpliceInfoSection(hexString: badISANHex), "Malformed ISAN with non-hex char should throw") + } + + /// Test: Fuzz with random data to ensure parser never crashes + /// The main purpose of this test is to ensure that parsing random base64 input does not crash the parser or the test runner. + /// The XCTAssertNoThrow assertion is used here for clarity, but the key goal is to validate parser stability, not the assertion itself. + func test_randomNoiseInput_shouldNotCrash() { + for _ in 0..<100 { + let randomData = Data((0..