isomorphic-git 1.43.2 → 1.43.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.
@@ -4528,37 +4528,12 @@ async function readObjectPacked({
4528
4528
  }
4529
4529
 
4530
4530
  // === Packfile Integrity Verification ===
4531
- // Performance optimization: use _checksumVerified flag to verify only once per packfile
4532
- if (!p._checksumVerified) {
4533
- const expectedShaFromIndex = p.packfileSha;
4534
-
4535
- // 1. Fast Check: Verify packfile trailer matches index record
4536
- // Use subarray instead of slice to avoid memory copy (zero-copy for large packfiles)
4537
- const packTrailer = pack.subarray(-20);
4538
- const packTrailerSha = Array.from(packTrailer)
4539
- .map(b => b.toString(16).padStart(2, '0'))
4540
- .join('');
4541
- if (packTrailerSha !== expectedShaFromIndex) {
4542
- throw new InternalError(
4543
- `Packfile trailer mismatch: expected ${expectedShaFromIndex}, got ${packTrailerSha}. The packfile may be corrupted.`
4544
- )
4545
- }
4546
-
4547
- // 2. Deep Integrity Check: Calculate actual SHA-1 of packfile payload.
4548
- // The Node package build swaps in a chunked implementation for large packs.
4549
- const actualPayloadSha = await shasumRange(pack, {
4550
- start: 0,
4551
- end: pack.length - 20,
4552
- });
4553
- if (actualPayloadSha !== expectedShaFromIndex) {
4554
- throw new InternalError(
4555
- `Packfile payload corrupted: calculated ${actualPayloadSha} but expected ${expectedShaFromIndex}. The packfile may have been tampered with.`
4556
- )
4557
- }
4558
-
4559
- // Mark as verified to prevent performance regression on subsequent reads
4560
- p._checksumVerified = true;
4531
+ // Performance optimization: verify only once per packfile.
4532
+ // Concurrent reads share the same verification promise.
4533
+ if (!p._checksumVerification) {
4534
+ p._checksumVerification = verifyPackfile(pack, p.packfileSha);
4561
4535
  }
4536
+ await p._checksumVerification;
4562
4537
 
4563
4538
  const result = await p.read({ oid, getExternalRefDelta });
4564
4539
  result.format = 'content';
@@ -4570,6 +4545,32 @@ async function readObjectPacked({
4570
4545
  return null
4571
4546
  }
4572
4547
 
4548
+ async function verifyPackfile(pack, expectedShaFromIndex) {
4549
+ // 1. Fast Check: Verify packfile trailer matches index record
4550
+ // Use subarray instead of slice to avoid memory copy (zero-copy for large packfiles)
4551
+ const packTrailer = pack.subarray(-20);
4552
+ const packTrailerSha = Array.from(packTrailer)
4553
+ .map(b => b.toString(16).padStart(2, '0'))
4554
+ .join('');
4555
+ if (packTrailerSha !== expectedShaFromIndex) {
4556
+ throw new InternalError(
4557
+ `Packfile trailer mismatch: expected ${expectedShaFromIndex}, got ${packTrailerSha}. The packfile may be corrupted.`
4558
+ )
4559
+ }
4560
+
4561
+ // 2. Deep Integrity Check: Calculate actual SHA-1 of packfile payload.
4562
+ // The Node package build swaps in a chunked implementation for large packs.
4563
+ const actualPayloadSha = await shasumRange(pack, {
4564
+ start: 0,
4565
+ end: pack.length - 20,
4566
+ });
4567
+ if (actualPayloadSha !== expectedShaFromIndex) {
4568
+ throw new InternalError(
4569
+ `Packfile payload corrupted: calculated ${actualPayloadSha} but expected ${expectedShaFromIndex}. The packfile may have been tampered with.`
4570
+ )
4571
+ }
4572
+ }
4573
+
4573
4574
  /**
4574
4575
  * @param {object} args
4575
4576
  * @param {import('../models/FileSystem.js').FileSystem} args.fs
package/managers/index.js CHANGED
@@ -4515,37 +4515,12 @@ async function readObjectPacked({
4515
4515
  }
4516
4516
 
4517
4517
  // === Packfile Integrity Verification ===
4518
- // Performance optimization: use _checksumVerified flag to verify only once per packfile
4519
- if (!p._checksumVerified) {
4520
- const expectedShaFromIndex = p.packfileSha;
4521
-
4522
- // 1. Fast Check: Verify packfile trailer matches index record
4523
- // Use subarray instead of slice to avoid memory copy (zero-copy for large packfiles)
4524
- const packTrailer = pack.subarray(-20);
4525
- const packTrailerSha = Array.from(packTrailer)
4526
- .map(b => b.toString(16).padStart(2, '0'))
4527
- .join('');
4528
- if (packTrailerSha !== expectedShaFromIndex) {
4529
- throw new InternalError(
4530
- `Packfile trailer mismatch: expected ${expectedShaFromIndex}, got ${packTrailerSha}. The packfile may be corrupted.`
4531
- )
4532
- }
4533
-
4534
- // 2. Deep Integrity Check: Calculate actual SHA-1 of packfile payload.
4535
- // The Node package build swaps in a chunked implementation for large packs.
4536
- const actualPayloadSha = await shasumRange(pack, {
4537
- start: 0,
4538
- end: pack.length - 20,
4539
- });
4540
- if (actualPayloadSha !== expectedShaFromIndex) {
4541
- throw new InternalError(
4542
- `Packfile payload corrupted: calculated ${actualPayloadSha} but expected ${expectedShaFromIndex}. The packfile may have been tampered with.`
4543
- )
4544
- }
4545
-
4546
- // Mark as verified to prevent performance regression on subsequent reads
4547
- p._checksumVerified = true;
4518
+ // Performance optimization: verify only once per packfile.
4519
+ // Concurrent reads share the same verification promise.
4520
+ if (!p._checksumVerification) {
4521
+ p._checksumVerification = verifyPackfile(pack, p.packfileSha);
4548
4522
  }
4523
+ await p._checksumVerification;
4549
4524
 
4550
4525
  const result = await p.read({ oid, getExternalRefDelta });
4551
4526
  result.format = 'content';
@@ -4557,6 +4532,32 @@ async function readObjectPacked({
4557
4532
  return null
4558
4533
  }
4559
4534
 
4535
+ async function verifyPackfile(pack, expectedShaFromIndex) {
4536
+ // 1. Fast Check: Verify packfile trailer matches index record
4537
+ // Use subarray instead of slice to avoid memory copy (zero-copy for large packfiles)
4538
+ const packTrailer = pack.subarray(-20);
4539
+ const packTrailerSha = Array.from(packTrailer)
4540
+ .map(b => b.toString(16).padStart(2, '0'))
4541
+ .join('');
4542
+ if (packTrailerSha !== expectedShaFromIndex) {
4543
+ throw new InternalError(
4544
+ `Packfile trailer mismatch: expected ${expectedShaFromIndex}, got ${packTrailerSha}. The packfile may be corrupted.`
4545
+ )
4546
+ }
4547
+
4548
+ // 2. Deep Integrity Check: Calculate actual SHA-1 of packfile payload.
4549
+ // The Node package build swaps in a chunked implementation for large packs.
4550
+ const actualPayloadSha = await shasumRange(pack, {
4551
+ start: 0,
4552
+ end: pack.length - 20,
4553
+ });
4554
+ if (actualPayloadSha !== expectedShaFromIndex) {
4555
+ throw new InternalError(
4556
+ `Packfile payload corrupted: calculated ${actualPayloadSha} but expected ${expectedShaFromIndex}. The packfile may have been tampered with.`
4557
+ )
4558
+ }
4559
+ }
4560
+
4560
4561
  /**
4561
4562
  * @param {object} args
4562
4563
  * @param {import('../models/FileSystem.js').FileSystem} args.fs