Skip to content

Commit

Permalink
Fix shaka-project#3608 MEDIA.BUFFER_READ_OUT_OF_BOUNDS error when CEA…
Browse files Browse the repository at this point in the history
… caption packets are empty

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.
  • Loading branch information
caridley committed Aug 31, 2021
1 parent 1fe1428 commit 06d1f55
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 @@ -87,7 +87,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 06d1f55

Please sign in to comment.