Skip to content

Commit

Permalink
Avoid RangeError in AAC PES overflow handling
Browse files Browse the repository at this point in the history
Followup to #3926
  • Loading branch information
Rob Walch committed Jun 1, 2021
1 parent 1b535e5 commit 6a9e0bd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/demux/tsdemuxer.ts
Expand Up @@ -941,17 +941,17 @@ class TSDemuxer implements Demuxer {
const data = pes.data;
if (aacOverFlow) {
this.aacOverFlow = null;
const frameMissingBytes = aacOverFlow.missing;
const frameOverflowBytes =
aacOverFlow.sample.unit.byteLength - frameMissingBytes;
const sampleLength = aacOverFlow.sample.unit.byteLength;
const frameMissingBytes = Math.min(aacOverFlow.missing, sampleLength);
const frameOverflowBytes = sampleLength - frameMissingBytes;
aacOverFlow.sample.unit.set(
data.subarray(0, frameMissingBytes),
frameOverflowBytes
);
track.samples.push(aacOverFlow.sample);

// logger.log(`AAC: append overflowing ${frameOverflowBytes} bytes to beginning of new PES`);
startOffset = frameMissingBytes;
startOffset = aacOverFlow.missing;
}
// look for ADTS header (0xFFFx)
let offset: number;
Expand Down

0 comments on commit 6a9e0bd

Please sign in to comment.