Skip to content

fix(segments): reject nan/inf timestamps - #567

Closed
kevin9327 wants to merge 1 commit into
Kruk2:mainfrom
kevin9327:fix/reject-non-finite-timestamps
Closed

kevin9327 wants to merge 1 commit into
Kruk2:mainfrom
kevin9327:fix/reject-non-finite-timestamps

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

parse_timestamp uses float() on each part, which also accepts nan, inf and infinity. The < 0 and >= 60 checks are both False for NaN, so these values got through:

  • parse_timestamp("nan") returns nan
  • parse_segments("1-inf") returns SegmentRange(1.0, inf) when no duration is given
  • parse_segments("nan-5") makes a segment whose start is NaN. That breaks the sorting and merging in normalize_segments.

Fix: raise ValueError("invalid timestamp") when any part is not finite.

Tests: I added nan/inf/1:nan/infinity to the reject cases and added test_parse_segments_rejects_non_finite_bounds. These fail on main (5 failures) and pass with the fix. All 24 tests in tests/test_segments.py pass.

AI-assistance note: I found and wrote this change with help from an AI coding assistant. I reviewed it and ran the tests myself.

kevin9327 added a commit to kevin9327/kevin9327 that referenced this pull request Oct 20, 2026
@Kruk2

Kruk2 commented Oct 22, 2026

Copy link
Copy Markdown
Owner

Nice catch, I didn't think about float() taking nan and inf. I put your commit on main as is (you're the author), it goes out with the next push. Thanks!

@Kruk2 Kruk2 closed this Oct 22, 2026
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.

2 participants