From 30fd63abf2d40b4fd9975515008f07b37508fb5a Mon Sep 17 00:00:00 2001 From: Sacha Elkaim <37674225+sachaelkaim@users.noreply.github.com> Date: Tue, 4 Apr 2023 05:12:21 -0400 Subject: [PATCH] fix: Handle empty media segments for Mp4VttParser (#5131) Fixes #4429 --- lib/text/mp4_vtt_parser.js | 4 ++++ test/text/mp4_vtt_parser_unit.js | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/text/mp4_vtt_parser.js b/lib/text/mp4_vtt_parser.js index 570e74f6e6..90f34eba08 100644 --- a/lib/text/mp4_vtt_parser.js +++ b/lib/text/mp4_vtt_parser.js @@ -97,6 +97,10 @@ shaka.text.Mp4VttParser = class { * @export */ parseMedia(data, time) { + if (!data.length) { + return []; + } + if (!this.timescale_) { // Missing timescale for VTT content. We should have seen the init // segment. diff --git a/test/text/mp4_vtt_parser_unit.js b/test/text/mp4_vtt_parser_unit.js index a6e945646e..46e49d0660 100644 --- a/test/text/mp4_vtt_parser_unit.js +++ b/test/text/mp4_vtt_parser_unit.js @@ -171,6 +171,14 @@ describe('Mp4VttParser', () => { verifyHelper(cues, result); }); + it('handles empty media segments', () => { + const parser = new shaka.text.Mp4VttParser(); + parser.parseInit(vttInitSegment); + const time = {periodStart: 0, segmentStart: 0, segmentEnd: 0, vttOffset: 0}; + const result = parser.parseMedia(new Uint8Array(0), time); + verifyHelper([], result); + }); + it('rejects init segment with no vtt', () => { const error = shaka.test.Util.jasmineError(new shaka.util.Error( shaka.util.Error.Severity.CRITICAL,