mediabunny 1.9.2 → 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.
@@ -4636,7 +4636,11 @@ var Mediabunny = (() => {
4636
4636
  totalSize = this.readU64();
4637
4637
  headerSize = 16;
4638
4638
  }
4639
- 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 };
4640
4644
  }
4641
4645
  };
4642
4646
 
@@ -12452,6 +12456,9 @@ ${cue.notes ?? ""}`;
12452
12456
  );
12453
12457
  const startPos = this.metadataReader.pos;
12454
12458
  const boxInfo = this.metadataReader.readBoxHeader();
12459
+ if (!boxInfo) {
12460
+ break;
12461
+ }
12455
12462
  if (boxInfo.name === "ftyp") {
12456
12463
  const majorBrand = this.metadataReader.readAscii(4);
12457
12464
  this.isQuickTime = majorBrand === "qt ";
@@ -12478,7 +12485,7 @@ ${cue.notes ?? ""}`;
12478
12485
  await this.metadataReader.reader.loadRange(potentialMfraPos, potentialMfraPos + 2 ** 16);
12479
12486
  this.metadataReader.pos = potentialMfraPos;
12480
12487
  const boxInfo = this.metadataReader.readBoxHeader();
12481
- if (boxInfo.name === "mfra") {
12488
+ if (boxInfo && boxInfo.name === "mfra") {
12482
12489
  await this.metadataReader.reader.loadRange(
12483
12490
  potentialMfraPos,
12484
12491
  potentialMfraPos + boxInfo.totalSize
@@ -12592,7 +12599,7 @@ ${cue.notes ?? ""}`;
12592
12599
  this.metadataReader.pos + MAX_BOX_HEADER_SIZE
12593
12600
  );
12594
12601
  const moofBoxInfo = this.metadataReader.readBoxHeader();
12595
- assert(moofBoxInfo.name === "moof");
12602
+ assert(moofBoxInfo?.name === "moof");
12596
12603
  const contentStart = this.metadataReader.pos;
12597
12604
  await this.metadataReader.reader.loadRange(contentStart, contentStart + moofBoxInfo.contentSize);
12598
12605
  this.metadataReader.pos = startPos;
@@ -12621,7 +12628,7 @@ ${cue.notes ?? ""}`;
12621
12628
  this.metadataReader.pos = currentFragment.moofOffset + currentFragment.moofSize;
12622
12629
  }
12623
12630
  let nextFragmentIsFirstFragment = this.metadataReader.pos === 0;
12624
- while (this.metadataReader.pos < startPos) {
12631
+ while (this.metadataReader.pos <= startPos - MIN_BOX_HEADER_SIZE) {
12625
12632
  if (currentFragment?.nextFragment) {
12626
12633
  currentFragment = currentFragment.nextFragment;
12627
12634
  this.metadataReader.pos = currentFragment.moofOffset + currentFragment.moofSize;
@@ -12632,6 +12639,9 @@ ${cue.notes ?? ""}`;
12632
12639
  );
12633
12640
  const startPos2 = this.metadataReader.pos;
12634
12641
  const boxInfo = this.metadataReader.readBoxHeader();
12642
+ if (!boxInfo) {
12643
+ break;
12644
+ }
12635
12645
  if (boxInfo.name === "moof") {
12636
12646
  const index3 = binarySearchExact(this.fragments, startPos2, (x) => x.moofOffset);
12637
12647
  let fragment2;
@@ -12666,12 +12676,18 @@ ${cue.notes ?? ""}`;
12666
12676
  readContiguousBoxes(totalSize) {
12667
12677
  const startIndex = this.metadataReader.pos;
12668
12678
  while (this.metadataReader.pos - startIndex <= totalSize - MIN_BOX_HEADER_SIZE) {
12669
- this.traverseBox();
12679
+ const foundBox = this.traverseBox();
12680
+ if (!foundBox) {
12681
+ break;
12682
+ }
12670
12683
  }
12671
12684
  }
12672
12685
  traverseBox() {
12673
12686
  const startPos = this.metadataReader.pos;
12674
12687
  const boxInfo = this.metadataReader.readBoxHeader();
12688
+ if (!boxInfo) {
12689
+ return false;
12690
+ }
12675
12691
  const boxEndPos = startPos + boxInfo.totalSize;
12676
12692
  switch (boxInfo.name) {
12677
12693
  case "mdia":
@@ -12899,6 +12915,9 @@ ${cue.notes ?? ""}`;
12899
12915
  for (let i = 0; i < entries; i++) {
12900
12916
  const startPos2 = this.metadataReader.pos;
12901
12917
  const sampleBoxInfo = this.metadataReader.readBoxHeader();
12918
+ if (!sampleBoxInfo) {
12919
+ break;
12920
+ }
12902
12921
  const lowercaseBoxName = sampleBoxInfo.name.toLowerCase();
12903
12922
  if (track.info.type === "video") {
12904
12923
  if (lowercaseBoxName === "avc1") {
@@ -13810,6 +13829,7 @@ ${cue.notes ?? ""}`;
13810
13829
  break;
13811
13830
  }
13812
13831
  this.metadataReader.pos = boxEndPos;
13832
+ return true;
13813
13833
  }
13814
13834
  };
13815
13835
  var IsobmffTrackBacking = class {
@@ -14192,6 +14212,9 @@ ${cue.notes ?? ""}`;
14192
14212
  await metadataReader.reader.loadRange(metadataReader.pos, metadataReader.pos + MAX_BOX_HEADER_SIZE);
14193
14213
  const startPos = metadataReader.pos;
14194
14214
  const boxInfo = metadataReader.readBoxHeader();
14215
+ if (!boxInfo) {
14216
+ break;
14217
+ }
14195
14218
  if (boxInfo.name === "moof") {
14196
14219
  const index = binarySearchExact(demuxer.fragments, startPos, (x) => x.moofOffset);
14197
14220
  let fragment;