Skip to content

Raise CaptionReadSyntaxError for malformed SRT instead of IndexError/ValueError - #417

Open
eeshsaxena wants to merge 1 commit into
pbs:mainfrom
eeshsaxena:fix/srt-malformed-timing
Open

Raise CaptionReadSyntaxError for malformed SRT instead of IndexError/ValueError#417
eeshsaxena wants to merge 1 commit into
pbs:mainfrom
eeshsaxena:fix/srt-malformed-timing

Conversation

@eeshsaxena

Copy link
Copy Markdown

The SRT reader raises bare IndexError/ValueError on some malformed input instead of a CaptionRead* error:

  • SRTReader().detect("1") -> IndexError (reads lines[1] without checking there are two lines)
  • SRTReader().read("1\n00:00:01,000 -->\nHi") -> IndexError from an empty end timestamp
  • a non-numeric timestamp -> ValueError

I made detect return False for content with fewer than two lines, and read validate the --> timing line and wrap timestamp parsing so a malformed timing line raises CaptionReadSyntaxError. Valid SRT parsing is unchanged.

Added tests for single-line detection and malformed timing; they fail on main with IndexError/ValueError and pass with the change, and the rest of the SRT tests still pass. Found it by fuzzing the readers with mutated captions.

…ValueError

SRTReader.detect read lines[1] without checking there were two lines, and
SRTReader.read parsed the '-->' timing line and each timestamp without
validating them. Single-line content, a timing line missing its end
timestamp, or a non-numeric timestamp raised a bare IndexError or ValueError.
detect now returns False for short content and read raises
CaptionReadSyntaxError for a malformed timing line.
@eeshsaxena
eeshsaxena requested a review from a team as a code owner August 15, 2026 02:09
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.

1 participant