Do not crash on empty WebVTT input or empty SRT cue text - #534
Closed
eeshsaxena wants to merge 1 commit into
Closed
Conversation
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.
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: SRT files will be tackled in a separate PR. I would very much appreciate your review. |
Author
Author
|
Closing in favor of #536, which takes a more complete approach to the WebVTT signature handling (proper spec-based first-line check, returning |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A couple of the subtitle readers raise on trivial input they otherwise tolerate.
vtt.to_modelon an empty document crashes:An empty file leaves only the
Noneterminator, and theSTARTstate callsline.startswith("WEBVTT")without theNonecheck the other states have. Separately,srt.to_modelhitsUnboundLocalErroron a cue whose text body is empty (a time line followed immediately by a blank line), sincesubtitle_textis only initialized once a non-empty text line is seen.I guarded the
Noneline in the WebVTTSTARTstate and initializedsubtitle_textwhen the paragraph is created. Added a test for each; the srt and vtt reader suites pass.