Repository navigation
[FIX] Skip corrupt H.264 data instead of exiting - #2492
Conversation
Feeding data that isn't H.264 to the AVC parser (for example a non-H.264 file concatenated after an H.264 one) made ccextractor panic or exit: - slice_header() indexed SLICE_TYPES with an unchecked slice_type (panic: "index out of bounds: the len is 10 but the index is 32"). The C slice_header() rejects values >= 10; the Rust port lost that check. - read_exp_golomb_unsigned() counted leading zeros without a limit, so a run of zero bytes asked read_bits() for hundreds of bits, which is fatal. - seq_parameter_set_rbsp() accepted any log2_max_frame_num_minus4 and log2_max_pic_order_cnt_lsb_minus4. slice_header() later uses them as bit counts, with the same fatal result. Skip such slices as the C code does, return an error for exp-Golomb codes with 64 or more leading zeros, and reject an SPS whose log2 fields exceed the H.264 limit of 12, keeping the previous one. do_nal errors are already logged and the NAL skipped.
CCExtractor CI platform finished running the test files on linux. 171/238 tests matched the approved output:
67 tests do not match the approved output. That is the pass/fail verdict. Whether this branch caused it is a separate question, answered below.
Compared with the tip of master — test 10124, commit 034fdbc:
Compared with the commit this branch was cut from: the same run as the tip of master (test 10124), so the comparison above already covers it. No test changes behaviour relative to the tip of master: every failure above fails there too, byte for byte. The approved output for those tests is out of date, which is a baseline to review rather than a regression in this branch. |
CCExtractor CI platform finished running the test files on windows. 171/238 tests matched the approved output:
67 tests do not match the approved output. That is the pass/fail verdict. Whether this branch caused it is a separate question, answered below.
Compared with the tip of master — test 10125, commit 034fdbc:
Compared with the commit this branch was cut from: the same run as the tip of master (test 10125), so the comparison above already covers it. No test changes behaviour relative to the tip of master: every failure above fails there too, byte for byte. The approved output for those tests is out of date, which is a baseline to review rather than a regression in this branch. |
In raising this pull request, I confirm the following (please check boxes):
Reason for this PR:
Sanity check:
Repro instructions:
Both samples are on the Sample Platform (
completed/). Each one works on its own, but together, on master:The process exits with code 134 and writes no output.
addf5e2f…has no H.264 SPS (Number of NAL_type_7: 0). Concatenated after an H.264 file, its video is fed to the H.264 parser as-is.Problem
The Rust AVC parser assumes well-formed H.264:
slice_typepanic.slice_header()usesslice_typeas an index intoSLICE_TYPESwithout checking it. The Cslice_header()rejectsslice_type >= 10(avc_functions.c), and the Rust port lost that check.read_exp_golomb_unsigned()counts leading zeros with no limit. A run of zero bytes then asksread_bits()for hundreds of bits, which is fatal:In next_bits: Argument is greater than the maximum bit number i.e. 64: 471!.seq_parameter_set_rbsp()accepts anylog2_max_frame_num_minus4andlog2_max_pic_order_cnt_lsb_minus4.slice_header()later uses them as bit counts, with the same fatal error.Fix
slice_typeis outsideSLICE_TYPES, as the C code does.BitstreamErrorfor an Exp-Golomb code with 64 or more leading zeros. Unit tests cover this and valid codes; the new test fails on master.do_nal()errors were already logged and the NAL skipped, so corrupt data now costs only the affected NALs.Verification
7236304c….ts) appended, its captions follow; the first one is merged with a leftover line from the first file.--service all) give byte-identical output and exit codes. None of the new messages appear on them.cargo testpasses (448src/rust, 57lib_ccxr), andcargo fmt --checkandcargo clippy -- -D warningsare clean in both crates.Not fixed here
addf5e2f…'s own 4 captions are still lost after an H.264 file, because its video keeps going to the H.264 parser. Switching codecs between concatenated inputs is a separate change.