Skip to content

Do not crash on empty WebVTT input or empty SRT cue text - #534

Closed
eeshsaxena wants to merge 1 commit into
sandflow:masterfrom
eeshsaxena:srt-vtt-empty-input
Closed

Do not crash on empty WebVTT input or empty SRT cue text#534
eeshsaxena wants to merge 1 commit into
sandflow:masterfrom
eeshsaxena:srt-vtt-empty-input

Conversation

@eeshsaxena

Copy link
Copy Markdown

A couple of the subtitle readers raise on trivial input they otherwise tolerate.

vtt.to_model on an empty document crashes:

import io, ttconv.vtt.reader as vtt
vtt.to_model(io.StringIO(""))   # AttributeError: 'NoneType' object has no attribute 'startswith'

An empty file leaves only the None terminator, and the START state calls line.startswith("WEBVTT") without the None check the other states have. Separately, srt.to_model hits UnboundLocalError on a cue whose text body is empty (a time line followed immediately by a blank line), since subtitle_text is only initialized once a non-empty text line is seen.

I guarded the None line in the WebVTT START state and initialized subtitle_text when the paragraph is created. Added a test for each; the srt and vtt reader suites pass.

Two subtitle readers raised on trivial input the parsers otherwise
tolerate:

- vtt.to_model on an empty document iterated straight to the None
  terminator in the START state and called None.startswith, raising
  AttributeError.
- srt.to_model hit UnboundLocalError on a cue whose text body is empty
  (a time line immediately followed by a blank line), because
  subtitle_text was only initialized when a non-empty text line was
  seen.

Guard the None line in the WebVTT START state, and initialize
subtitle_text when the paragraph is created.
@palemieux

Copy link
Copy Markdown
Contributor

@eeshsaxena Thanks for raising these parsing issues. It looks like the VTT reader never handled VTT files with incorrect signatures according to the specification. I have proposed a fix at:

#536

SRT files will be tackled in a separate PR.

I would very much appreciate your review.

@eeshsaxena

Copy link
Copy Markdown
Author

Thanks for taking this on. Your signature-check approach in #536 is better than my guard, happy to see it handled per the spec. Left one note there about the None return needing handling at the tt.py call site. Fine to close this in favour of #536.

@eeshsaxena

Copy link
Copy Markdown
Author

Closing in favor of #536, which takes a more complete approach to the WebVTT signature handling (proper spec-based first-line check, returning None on a bad signature, and broader test coverage). I left a review there with two small notes. Thanks @palemieux for picking this up.

@eeshsaxena eeshsaxena closed this Aug 17, 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