Skip to content

Commit

Permalink
Fixup max safe integer check for open ended byteranges with nonzero s…
Browse files Browse the repository at this point in the history
…tart
  • Loading branch information
iamboorrito committed Jun 28, 2024
1 parent deac50e commit e0955a8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
14 changes: 7 additions & 7 deletions src/loader/fragment-preloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,10 @@ export default class FragmentPreloader extends FragmentLoader {
this.abort();
}

this.log(
`[${this.getStateString()}] create request for [${frag.type}] ${
frag.sn
}:${part?.index}`,
);

let loadPromise;
if (part !== undefined) {
// TODO: Use fetch loader to progressively load open-ended byterange requests
if (part.byteRangeEndOffset === 2 ** 53 - 1) {
if (part?.byteRangeEndOffset === Number.MAX_SAFE_INTEGER) {
return;
} else {
loadPromise = this.loadPart(frag, part, noop);
Expand All @@ -116,6 +110,12 @@ export default class FragmentPreloader extends FragmentLoader {
loadPromise = this.load(frag, noop);
}

this.log(
`[${this.getStateString()}] create request for [${frag.type}] ${
frag.sn
}:${part?.index}`,
);

const request = {
frag,
part,
Expand Down
8 changes: 7 additions & 1 deletion src/loader/fragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ export class BaseSegment {
} else {
start = parseInt(params[1]);
}
this._byteRange = [start, parseInt(params[0]) + start];
const bytelength = parseInt(params[0]);
const offsetEnd =
Number.isSafeInteger(bytelength) && bytelength !== Number.MAX_SAFE_INTEGER
? start + bytelength
: Number.MAX_SAFE_INTEGER;

this._byteRange = [start, offsetEnd];
}

get byteRange(): [number, number] | [] {
Expand Down
11 changes: 6 additions & 5 deletions src/loader/m3u8-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -756,11 +756,12 @@ export default class M3U8Parser {
preloadHintAttrs['BYTERANGE-LENGTH']
) {
const byteRangeStartOffset = preloadHintAttrs['BYTERANGE-START'];
let byteRangeLength = preloadHintAttrs['BYTERANGE-LENGTH'];
if (byteRangeLength <= 0) {
byteRangeLength = 2 ** 53 - 1;
}
if (isFinite(byteRangeLength) && isFinite(byteRangeStartOffset)) {

if (isFinite(byteRangeStartOffset)) {
let byteRangeLength = preloadHintAttrs['BYTERANGE-LENGTH'];
if (!isFinite(byteRangeLength) || byteRangeLength <= 0) {
byteRangeLength = Number.MAX_SAFE_INTEGER;
}
byteRange = `${byteRangeLength}@${byteRangeStartOffset}`;
}
}
Expand Down

0 comments on commit e0955a8

Please sign in to comment.