[FIX] Handle negative PTS in teletext process_page() — replace .expect() on to_srt_time() with graceful fallback #2240
Open
NexionisJake wants to merge 1 commit intoCCExtractor:masterfrom
Conversation
show_timestamp.to_srt_time().expect() and hide_timestamp.to_srt_time().expect() in TeletextContext::process_page() panicked for any negative Timestamp value. Negative timestamps are common in broadcast captures with wrap-around or uninitialized PTS — crashing after potentially processing an entire file. to_srt_time() → as_hms_millis() → i64::try_into::<u64>() returns OutOfRangeError for negative values; .expect() made this fatal. Fix: process_page() already returns Option<Subtitle>, so replace both .expect() calls with .ok()? — silently skipping the subtitle when the timestamp is out of range, matching the function's existing None-on-empty contract. Fixes CCExtractor#2233
Collaborator
CCExtractor CI platform finished running the test files on linux. Below is a summary of the test results, when compared to test for commit d56a6be...:
Your PR breaks these cases:
NOTE: The following tests have been failing on the master branch as well as the PR:
Congratulations: Merging this PR would fix the following tests:
It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you). Check the result page for more info. |
Collaborator
CCExtractor CI platform finished running the test files on windows. Below is a summary of the test results, when compared to test for commit d56a6be...:
Your PR breaks these cases:
NOTE: The following tests have been failing on the master branch as well as the PR:
Congratulations: Merging this PR would fix the following tests:
It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you). Check the result page for more info. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In raising this pull request, I confirm the following:
Reason for this PR:
Sanity check:
Repro instructions:
Feed CCExtractor any broadcast teletext stream with negative or wrap-around PTS values. The crash manifests during
subtitle output:
thread 'main' panicked at 'could not format to SRT time', src/rust/lib_ccxr/src/teletext.rs:1010
Minimal Rust reproducer:
use lib_ccxr::time::units::Timestamp;
let ts = Timestamp::from_millis(-1);
ts.to_srt_time().expect("could not format to SRT time"); // panics
Root Cause
TeletextContext::process_page() called:
show_timestamp.to_srt_time().expect("could not format to SRT time")
hide_timestamp.to_srt_time().expect("could not format to SRT time")
to_srt_time() → as_hms_millis() → i64::try_into::() returns OutOfRangeError for any negative value. .expect() made
this an unconditional crash, potentially after an entire file was processed successfully. Negative timestamps are common
in real-world broadcast captures with PTS wrap-around or uninitialized PTS.
Fix
process_page() already returns Option and already returns None for empty pages. Replacing both .expect() calls
with .ok()? extends this existing contract: a subtitle with an out-of-range timestamp is silently skipped — the same
outcome as if the page were empty.
// Before
let timecode_show = self.page_buffer.show_timestamp.to_srt_time()
.expect("could not format to SRT time");
// After
// Negative timestamps occur with wrap-around/uninitialized PTS in broadcast captures
let timecode_show = self.page_buffer.show_timestamp.to_srt_time().ok()?;
Testing
Fixes #2233