Skip to content

[FIX] Widen numerical sequence parsing to u64 to prevent overflow panic - #2403

Open
muntasir-396 wants to merge 1 commit into
CCExtractor:masterfrom
muntasir-396:fix/file-sequence-overflow-panic
Open

muntasir-396 wants to merge 1 commit into
CCExtractor:masterfrom
muntasir-396:fix/file-sequence-overflow-panic

Conversation

@muntasir-396

Copy link
Copy Markdown

Summary

Fixes #2402.

When an input filename specifies numerical sequence expansion with a + suffix (e.g. capture_20261019120000+.ts), add_file_sequence() in src/rust/src/parser.rs previously parsed the sequence number using num.parse::<i32>().unwrap().

If the numeric segment exceeds i32::MAX (2,147,483,647), common in timestamp-based filenames (e.g. YYYYMMDDHHMMSS), the parser panicked with ParseIntError { kind: PosOverflow }.

Changes

  1. Widen to u64: Parse the numeric portion as u64 instead of i32.
  2. Safe Error Handling: Replace .unwrap() with let Ok(mut i) = num.parse::<u64>() else { ... }, falling back gracefully to appending the literal filename if parsing fails or overflows u64::MAX.
  3. Safe Increment: Use checked_add(1) when generating subsequent sequence filenames to avoid arithmetic overflow.
  4. Unit Tests: Added unit tests verifying that large numbers (> i32::MAX), values exceeding u64::MAX, and suffixes without digits do not panic, and verifying sequential expansion of existing files.

When an input filename specifies numerical sequence expansion with a '+'
suffix (e.g. capture_20261019120000+.ts), add_file_sequence() extracted
the numeric segment and parsed it using num.parse::<i32>().unwrap().

If the numeric segment exceeded i32::MAX (common in timestamp-based
filenames), the parser panicked with ParseIntError { kind: PosOverflow }.

This commit:
- Parses the numeric sequence segment as u64 instead of i32.
- Handles parse failures gracefully by falling back to appending the
  file to the queue without panicking.
- Uses checked_add(1) to avoid potential overflow when generating the
  next sequence candidate.
- Adds unit tests verifying that large numbers (> i32::MAX), values
  exceeding u64::MAX, and filenames without digits do not panic, and
  verifies sequence expansion with real files.

Fixes CCExtractor#2402.
@muntasir-396
muntasir-396 force-pushed the fix/file-sequence-overflow-panic branch from 60a71d8 to b8de24c Compare October 19, 2026 15:06
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.

[BUG] Filename sequence expansion (+) panics on numeric values exceeding i32::MAX

1 participant