Skip to content

Raise TimestampParseError on an out-of-range timestamp - #100

Open
eeshsaxena wants to merge 3 commits into
cdown:masterfrom
eeshsaxena:fix/timestamp-overflow
Open

Raise TimestampParseError on an out-of-range timestamp#100
eeshsaxena wants to merge 3 commits into
cdown:masterfrom
eeshsaxena:fix/timestamp-overflow

Conversation

@eeshsaxena

Copy link
Copy Markdown

srt_timestamp_to_timedelta leaks OverflowError on a syntactically valid but absurdly large timestamp:

>>> import srt
>>> srt.srt_timestamp_to_timedelta("9999999999999999999:00:00,000")
OverflowError: Python int too large to convert to C int

RGX_TIMESTAMP_FIELD is [0-9]+ (an unbounded digit run), so the value matches the regex, but the resulting int overflows timedelta's C-level day count. The hours, seconds and milliseconds fields are all affected, and parse() propagates it, even though both functions document TimestampParseError / SRTParseError as the failure mode.

The fix wraps the timedelta construction and re-raises as TimestampParseError, matching the existing 'unparseable timestamp' path. Added a parametrized test covering the hours, seconds and milliseconds fields.

Igor Kozyrenko and others added 3 commits November 2, 2023 00:35
This is no longer supported or operational.
The timestamp regex matches unbounded digit runs, so a value like
"9999999999999999999:00:00,000" parses but overflows timedelta's C-level day
count, and srt_timestamp_to_timedelta leaked a raw OverflowError. parse() then
propagated it too, despite both being documented to raise TimestampParseError /
SRTParseError. Catch the overflow and raise TimestampParseError instead.
@eeshsaxena

Copy link
Copy Markdown
Author

Hi! Gentle nudge on this one whenever you have some bandwidth. It's a small, self-contained fix (Raise TimestampParseError on an out-of-range timestamp), and it's currently mergeable with no conflicts. No urgency at all, and I'm happy to make any changes you'd like. Thanks for maintaining srt!

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