Skip to content

Commit

Permalink
Safe check for value over 2^63
Browse files Browse the repository at this point in the history
  • Loading branch information
robwalch committed Mar 24, 2023
1 parent 2726f52 commit 6c493ea
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/utils/mp4-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,17 +367,17 @@ export function getStartDTS(
if (track) {
let baseTime = readUint32(tfdt, 4);
if (version === 1) {
baseTime *= Math.pow(2, 32);
baseTime += readUint32(tfdt, 8);
// If value is too large, assume signed 64-bit. Negative track fragment decode times are invalid, but they exist in the wild.
// This prevents large values from being used for initPTS, which can cause playlist sync issues.
// https://github.com/video-dev/hls.js/issues/5303
if (baseTime > Math.pow(2, 63)) {
if (baseTime === UINT32_MAX) {
logger.warn(
`[mp4-demuxer]: Found large track fragment decode time of ${baseTime}, using last result ${result} or playlist time instead.`
`[mp4-demuxer]: Ignoring assumed invalid signed 64-bit track fragment decode time`
);
return result;
}
baseTime *= UINT32_MAX + 1;
baseTime += readUint32(tfdt, 8);
}
// assume a 90kHz clock if no timescale was specified
const scale = track.timescale || 90e3;
Expand Down

0 comments on commit 6c493ea

Please sign in to comment.