Skip to content

Commit

Permalink
fix(cea): Fix BUFFER_READ_OUT_OF_BOUNDS error when CEA caption packet…
Browse files Browse the repository at this point in the history
…s are empty (shaka-project#3609)

Added check for empty caption packets in closed_caption_parser.

Added a unit test that verifies the closed_caption_parser now works with a video segment that contains empty caption packets.

Fixes shaka-project#3608
  • Loading branch information
caridley authored Sep 9, 2021
1 parent 23e0d76 commit 97ba4df
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/media/closed_caption_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ shaka.media.ClosedCaptionParser = class {
for (const captionPacket of captionPackets) {
const uint8ArrayData =
shaka.util.BufferUtils.toUint8(captionPacket.packet);
this.ceaDecoder_.extract(uint8ArrayData, captionPacket.pts);
if (uint8ArrayData.length > 0) {
this.ceaDecoder_.extract(uint8ArrayData, captionPacket.pts);
}
}

// Decode and return the parsed captions.
Expand Down
15 changes: 15 additions & 0 deletions test/media/closed_caption_parser_unit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
goog.require('shaka.media.ClosedCaptionParser');
goog.require('shaka.test.Util');

describe('ClosedCaptionParser', () => {
it('can handle empty caption packets', async () => {
const initSegment = await shaka.test.Util.fetch(
'base/test/test/assets/empty_caption_video_init.mp4');
const videoSegment = await shaka.test.Util.fetch(
'base/test/test/assets/empty_caption_video_segment.mp4');
const parser = new shaka.media.ClosedCaptionParser();
parser.init(initSegment);
parser.parseFrom(videoSegment);
});
});

Binary file added test/test/assets/empty_caption_video_init.mp4
Binary file not shown.
Binary file added test/test/assets/empty_caption_video_segment.mp4
Binary file not shown.

0 comments on commit 97ba4df

Please sign in to comment.