Skip to content

Commit

Permalink
Improved error messages in box header parsing function.
Browse files Browse the repository at this point in the history
  • Loading branch information
BTOdell committed Aug 3, 2021
1 parent ad7d189 commit 8948c47
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/core/src/Box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,21 @@ export namespace BoxHeader {
let offset: number = 8;
let largesize: bigint | undefined;
if (size === 0) {
throw new Error("box cannot extend indefinitely (type: " + type + ")");
throw new Error("Box cannot extend indefinitely (type: " + type +
" | 0x" + buffer.toString("hex", 4, 8).padStart(8, "0") + ")");
} else if (size === 1) {
if (buffer.length < (headerLength += 8)) {
return headerLength;
}
largesize = buffer.readBigUInt64BE(offset).valueOf();
if (largesize > MAX_SAFE_BIGINT) {
throw new Error("largesize mode is not supported");
throw new Error("Largesize mode is not supported");
}
offset += 8;
// If the largesize can be stored in the normal size, then do so
size = Number(largesize);
} else if (size < headerLength) {
throw new Error("invalid box size: " + size);
throw new Error("Invalid box size: " + size);
}
// Check for user-defined type
let usertype: Buffer | undefined;
Expand Down

0 comments on commit 8948c47

Please sign in to comment.