mediabunny 1.9.1 → 1.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1766,6 +1766,7 @@ var Mediabunny = (() => {
1766
1766
  async addEncodedAudioPacket(track, packet, meta) {
1767
1767
  const release = await this.mutex.acquire();
1768
1768
  try {
1769
+ this.validateAndNormalizeTimestamp(track, packet.timestamp, packet.type === "key");
1769
1770
  if (!this.audioSpecificConfig) {
1770
1771
  validateAudioChunkMetadata(meta);
1771
1772
  const description = meta?.decoderConfig?.description;
@@ -4635,7 +4636,11 @@ var Mediabunny = (() => {
4635
4636
  totalSize = this.readU64();
4636
4637
  headerSize = 16;
4637
4638
  }
4638
- return { name, totalSize, headerSize, contentSize: totalSize - headerSize };
4639
+ const contentSize = totalSize - headerSize;
4640
+ if (contentSize < 0) {
4641
+ return null;
4642
+ }
4643
+ return { name, totalSize, headerSize, contentSize };
4639
4644
  }
4640
4645
  };
4641
4646
 
@@ -12451,6 +12456,9 @@ ${cue.notes ?? ""}`;
12451
12456
  );
12452
12457
  const startPos = this.metadataReader.pos;
12453
12458
  const boxInfo = this.metadataReader.readBoxHeader();
12459
+ if (!boxInfo) {
12460
+ break;
12461
+ }
12454
12462
  if (boxInfo.name === "ftyp") {
12455
12463
  const majorBrand = this.metadataReader.readAscii(4);
12456
12464
  this.isQuickTime = majorBrand === "qt ";
@@ -12473,11 +12481,15 @@ ${cue.notes ?? ""}`;
12473
12481
  this.metadataReader.pos = sourceSize - 4;
12474
12482
  const lastWord = this.metadataReader.readU32();
12475
12483
  const potentialMfraPos = sourceSize - lastWord;
12476
- if (potentialMfraPos >= 0 && potentialMfraPos < sourceSize) {
12477
- await this.metadataReader.reader.loadRange(potentialMfraPos, sourceSize);
12484
+ if (potentialMfraPos >= 0 && potentialMfraPos <= sourceSize - MAX_BOX_HEADER_SIZE) {
12485
+ await this.metadataReader.reader.loadRange(potentialMfraPos, potentialMfraPos + 2 ** 16);
12478
12486
  this.metadataReader.pos = potentialMfraPos;
12479
12487
  const boxInfo = this.metadataReader.readBoxHeader();
12480
- if (boxInfo.name === "mfra") {
12488
+ if (boxInfo && boxInfo.name === "mfra") {
12489
+ await this.metadataReader.reader.loadRange(
12490
+ potentialMfraPos,
12491
+ potentialMfraPos + boxInfo.totalSize
12492
+ );
12481
12493
  this.readContiguousBoxes(boxInfo.contentSize);
12482
12494
  }
12483
12495
  }
@@ -12587,7 +12599,7 @@ ${cue.notes ?? ""}`;
12587
12599
  this.metadataReader.pos + MAX_BOX_HEADER_SIZE
12588
12600
  );
12589
12601
  const moofBoxInfo = this.metadataReader.readBoxHeader();
12590
- assert(moofBoxInfo.name === "moof");
12602
+ assert(moofBoxInfo?.name === "moof");
12591
12603
  const contentStart = this.metadataReader.pos;
12592
12604
  await this.metadataReader.reader.loadRange(contentStart, contentStart + moofBoxInfo.contentSize);
12593
12605
  this.metadataReader.pos = startPos;
@@ -12616,7 +12628,7 @@ ${cue.notes ?? ""}`;
12616
12628
  this.metadataReader.pos = currentFragment.moofOffset + currentFragment.moofSize;
12617
12629
  }
12618
12630
  let nextFragmentIsFirstFragment = this.metadataReader.pos === 0;
12619
- while (this.metadataReader.pos < startPos) {
12631
+ while (this.metadataReader.pos <= startPos - MIN_BOX_HEADER_SIZE) {
12620
12632
  if (currentFragment?.nextFragment) {
12621
12633
  currentFragment = currentFragment.nextFragment;
12622
12634
  this.metadataReader.pos = currentFragment.moofOffset + currentFragment.moofSize;
@@ -12627,6 +12639,9 @@ ${cue.notes ?? ""}`;
12627
12639
  );
12628
12640
  const startPos2 = this.metadataReader.pos;
12629
12641
  const boxInfo = this.metadataReader.readBoxHeader();
12642
+ if (!boxInfo) {
12643
+ break;
12644
+ }
12630
12645
  if (boxInfo.name === "moof") {
12631
12646
  const index3 = binarySearchExact(this.fragments, startPos2, (x) => x.moofOffset);
12632
12647
  let fragment2;
@@ -12661,12 +12676,18 @@ ${cue.notes ?? ""}`;
12661
12676
  readContiguousBoxes(totalSize) {
12662
12677
  const startIndex = this.metadataReader.pos;
12663
12678
  while (this.metadataReader.pos - startIndex <= totalSize - MIN_BOX_HEADER_SIZE) {
12664
- this.traverseBox();
12679
+ const foundBox = this.traverseBox();
12680
+ if (!foundBox) {
12681
+ break;
12682
+ }
12665
12683
  }
12666
12684
  }
12667
12685
  traverseBox() {
12668
12686
  const startPos = this.metadataReader.pos;
12669
12687
  const boxInfo = this.metadataReader.readBoxHeader();
12688
+ if (!boxInfo) {
12689
+ return false;
12690
+ }
12670
12691
  const boxEndPos = startPos + boxInfo.totalSize;
12671
12692
  switch (boxInfo.name) {
12672
12693
  case "mdia":
@@ -12894,6 +12915,9 @@ ${cue.notes ?? ""}`;
12894
12915
  for (let i = 0; i < entries; i++) {
12895
12916
  const startPos2 = this.metadataReader.pos;
12896
12917
  const sampleBoxInfo = this.metadataReader.readBoxHeader();
12918
+ if (!sampleBoxInfo) {
12919
+ break;
12920
+ }
12897
12921
  const lowercaseBoxName = sampleBoxInfo.name.toLowerCase();
12898
12922
  if (track.info.type === "video") {
12899
12923
  if (lowercaseBoxName === "avc1") {
@@ -13805,6 +13829,7 @@ ${cue.notes ?? ""}`;
13805
13829
  break;
13806
13830
  }
13807
13831
  this.metadataReader.pos = boxEndPos;
13832
+ return true;
13808
13833
  }
13809
13834
  };
13810
13835
  var IsobmffTrackBacking = class {
@@ -14187,6 +14212,9 @@ ${cue.notes ?? ""}`;
14187
14212
  await metadataReader.reader.loadRange(metadataReader.pos, metadataReader.pos + MAX_BOX_HEADER_SIZE);
14188
14213
  const startPos = metadataReader.pos;
14189
14214
  const boxInfo = metadataReader.readBoxHeader();
14215
+ if (!boxInfo) {
14216
+ break;
14217
+ }
14190
14218
  if (boxInfo.name === "moof") {
14191
14219
  const index = binarySearchExact(demuxer.fragments, startPos, (x) => x.moofOffset);
14192
14220
  let fragment;