Repository navigation
[FIX] Reject malformed extraction times before they abort the parser - #2374
Conversation
Generated-by: OpenAI Codex
kaihere14
left a comment
There was a problem hiding this comment.
Thanks for this. The unwrap() on user input in the FFI path is a real crash, and moving the check into clap is the right place for it.
I checked it out locally and ran the suite. cargo test passes (408 in the main crate, 48 + 45 in lib_ccxr), and fmt, clippy and git diff --check are clean.
A few things I'd like fixed in this PR, not a follow-up:
- 255-hour cap: --startat 256:00:00 is rejected because of the u8 parse, but the doc comment doesn't say so. Could you add a line about the limit to the --startat doc in args.rs?
- Typo: the error text is error ocurred during parsing (lib_ccxr/src/time/units.rs). It's shared with other timestamp code, but this PR is what now surfaces it to users. Could you fix it to occurred here?
Two smaller things, optional in this PR:
- --startat +5 is accepted as 5 seconds, because u8 parsing allows a leading +. Fine to leave, just worth a conscious call.
- --endat earlier than --startat isn't checked. That was already true before this PR, so I don't think it should block.
Otherwise this looks good to me.
CCExtractor CI platform finished running the test files on linux. 171/237 tests matched the approved output:
66 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 9642, commit 97a0d24:
Compared with the commit this branch was cut from: the same run as the tip of master (test 9642), 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/237 tests matched the approved output:
66 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 9643, commit 97a0d24:
Compared with the commit this branch was cut from: the same run as the tip of master (test 9643), 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#2374 already validates --startat and --endat in clap. Do the same for the six start/end credits timing options and drop the helper this branch added.
Reason for this PR:
Sanity check:
--startatand--endatcurrently accept malformed strings through clap, then unwrap a failedstringztoms()result. In the C-facingccxr_parse_parametersentry point, that panic cannot unwind across the ABI boundary and aborts the process.Parse both options as
Timestampvalues with the existing time parser during clap validation.Options::parse_parametersthen copies the validated values directly. Valid seconds,MM:SS, andHH:MM:SSinputs keep their existing meaning and range restrictions.Reproduction sample
Create a minimal SCC input:
The file content does not affect this failure: it happens during argument parsing, before the input is opened. The added
test_extraction_time_ffi_returns_errorcalls the same production C-facing entry point with these argument samples. With the original argument types and unwraps restored, it aborts withSIGABRTat theOption::unwrap()inparser.rs. With the fix, both options return an argument error instead. This validation uses the actual FFI parser.Tests also cover empty, nonnumeric, out-of-range, missing-component, and extra-component values for both options, plus valid seconds,
MM:SS, andHH:MM:SSvalues propagated into the extraction boundaries.Validation
Using the repository's pinned Rust 1.99.0:
lib_ccxr: 48 unit tests and 45 documentation tests passed.cargo clippy -- -D warningspassed for both crates.git diff --checkpassed.AI assistance: OpenAI Codex assisted with implementation and testing.
Upstream CI follow-up
The Linux and Windows media comparisons report zero regressions against master: all 66 approved-output mismatches also occur on master, byte for byte. Rust tests, formatting, and the other reported build checks passed. Three macOS CMake jobs failed at linking against SDK stub libraries with an
unknown architectureerror. The maintainer merged this change after review.