isomorphic-git 1.37.1 → 1.37.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.
package/README.md CHANGED
@@ -77,7 +77,10 @@ git.clone({ fs, http, dir, url: 'https://github.com/isomorphic-git/lightning-fs'
77
77
  ```
78
78
 
79
79
  If you're using `isomorphic-git` in the browser, you'll need something that emulates the `fs` API.
80
- The easiest to setup and most performant library is [LightningFS](https://github.com/isomorphic-git/lightning-fs) which is written and maintained by the same author and is part of the `isomorphic-git` suite.
80
+ The easiest to setup and most performant library is [LightningFS](https://github.com/isomorphic-git/lightning-fs) which is written and maintained by the same author and is part of the `isomorphic-git` suite.
81
+
82
+ ⚠️ LightningFS may apply file operations out of order, which can lead to repository corruption if the process crashes. You can mitigate this by calling `fs.flush()` after Git operations.
83
+
81
84
  If LightningFS doesn't meet your requirements, isomorphic-git should also work with [ZenFS](https://github.com/zen-fs/core) and [Filer](https://github.com/filerjs/filer).
82
85
  Instead of `isomorphic-git/http/node` this time import `isomorphic-git/http/web`:
83
86
 
@@ -414,6 +417,9 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
414
417
  <td align="center"><a href="https://github.com/Andarist"><img src="https://avatars.githubusercontent.com/u/9800850?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Mateusz Burzyński</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=Andarist" title="Code">💻</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=Andarist" title="Tests">⚠️</a></td>
415
418
  <td align="center"><a href="https://github.com/IAmSSH"><img src="https://avatars.githubusercontent.com/u/34162350?v=4?s=60" width="60px;" alt=""/><br /><sub><b>iamssh</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=IAmSSH" title="Code">💻</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=IAmSSH" title="Documentation">📖</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=IAmSSH" title="Tests">⚠️</a></td>
416
419
  </tr>
420
+ <tr>
421
+ <td align="center"><a href="https://github.com/N0zoM1z0"><img src="https://avatars.githubusercontent.com/u/161784452?v=4?s=60" width="60px;" alt=""/><br /><sub><b>N0zoM1z0</b></sub></a><br /><a href="#security-N0zoM1z0" title="Security">🛡️</a></td>
422
+ </tr>
417
423
  </table>
418
424
 
419
425
  <!-- markdownlint-restore -->
package/index.cjs CHANGED
@@ -3395,6 +3395,40 @@ async function readObjectPacked({
3395
3395
  const packFile = indexFile.replace(/idx$/, 'pack');
3396
3396
  p.pack = fs.read(packFile);
3397
3397
  }
3398
+ const pack = await p.pack;
3399
+
3400
+ // === Packfile Integrity Verification ===
3401
+ // Performance optimization: use _checksumVerified flag to verify only once per packfile
3402
+ if (!p._checksumVerified) {
3403
+ const expectedShaFromIndex = p.packfileSha;
3404
+
3405
+ // 1. Fast Check: Verify packfile trailer matches index record
3406
+ // Use subarray instead of slice to avoid memory copy (zero-copy for large packfiles)
3407
+ const packTrailer = pack.subarray(-20);
3408
+ const packTrailerSha = Array.from(packTrailer)
3409
+ .map(b => b.toString(16).padStart(2, '0'))
3410
+ .join('');
3411
+ if (packTrailerSha !== expectedShaFromIndex) {
3412
+ throw new InternalError(
3413
+ `Packfile trailer mismatch: expected ${expectedShaFromIndex}, got ${packTrailerSha}. The packfile may be corrupted.`
3414
+ )
3415
+ }
3416
+
3417
+ // 2. Deep Integrity Check: Calculate actual SHA-1 of packfile payload
3418
+ // This ensures true data integrity by verifying the entire packfile content
3419
+ // Use subarray for zero-copy reading of large files
3420
+ const payload = pack.subarray(0, -20);
3421
+ const actualPayloadSha = await shasum(payload);
3422
+ if (actualPayloadSha !== expectedShaFromIndex) {
3423
+ throw new InternalError(
3424
+ `Packfile payload corrupted: calculated ${actualPayloadSha} but expected ${expectedShaFromIndex}. The packfile may have been tampered with.`
3425
+ )
3426
+ }
3427
+
3428
+ // Mark as verified to prevent performance regression on subsequent reads
3429
+ p._checksumVerified = true;
3430
+ }
3431
+
3398
3432
  const result = await p.read({ oid, getExternalRefDelta });
3399
3433
  result.format = 'content';
3400
3434
  result.source = `objects/pack/${filename.replace(/idx$/, 'pack')}`;
@@ -5167,7 +5201,7 @@ function assertParameter(name, value) {
5167
5201
  /**
5168
5202
  * discoverGitdir
5169
5203
  *
5170
- * When processing git commands on a submodule determine
5204
+ * When processing git commands on a submodule or worktree, determine
5171
5205
  * the actual git directory based on the contents of the .git file.
5172
5206
  *
5173
5207
  * Otherwise (if sent a directory) return that directory as-is.
@@ -5184,6 +5218,11 @@ function assertParameter(name, value) {
5184
5218
  *
5185
5219
  */
5186
5220
 
5221
+ // Check if a path is absolute (Unix / or Windows drive letter like C:\ or C:/)
5222
+ function isAbsolute(filepath) {
5223
+ return filepath.startsWith('/') || /^[a-zA-Z]:[\\/]/.test(filepath)
5224
+ }
5225
+
5187
5226
  async function discoverGitdir({ fsp, dotgit }) {
5188
5227
  assertParameter('fsp', fsp);
5189
5228
  assertParameter('dotgit', dotgit);
@@ -5198,6 +5237,10 @@ async function discoverGitdir({ fsp, dotgit }) {
5198
5237
  ._readFile(dotgit, 'utf8')
5199
5238
  .then(contents => contents.trimRight().substr(8))
5200
5239
  .then(submoduleGitdir => {
5240
+ // Worktrees use absolute gitdir paths; submodules use relative ones.
5241
+ if (isAbsolute(submoduleGitdir)) {
5242
+ return submoduleGitdir
5243
+ }
5201
5244
  const gitdir = join(dirname(dotgit), submoduleGitdir);
5202
5245
  return gitdir
5203
5246
  })
@@ -9261,8 +9304,8 @@ function filterCapabilities(server, client) {
9261
9304
 
9262
9305
  const pkg = {
9263
9306
  name: 'isomorphic-git',
9264
- version: '1.37.1',
9265
- agent: 'git/isomorphic-git@1.37.1',
9307
+ version: '1.37.3',
9308
+ agent: 'git/isomorphic-git@1.37.3',
9266
9309
  };
9267
9310
 
9268
9311
  class FIFO {
package/index.js CHANGED
@@ -3389,6 +3389,40 @@ async function readObjectPacked({
3389
3389
  const packFile = indexFile.replace(/idx$/, 'pack');
3390
3390
  p.pack = fs.read(packFile);
3391
3391
  }
3392
+ const pack = await p.pack;
3393
+
3394
+ // === Packfile Integrity Verification ===
3395
+ // Performance optimization: use _checksumVerified flag to verify only once per packfile
3396
+ if (!p._checksumVerified) {
3397
+ const expectedShaFromIndex = p.packfileSha;
3398
+
3399
+ // 1. Fast Check: Verify packfile trailer matches index record
3400
+ // Use subarray instead of slice to avoid memory copy (zero-copy for large packfiles)
3401
+ const packTrailer = pack.subarray(-20);
3402
+ const packTrailerSha = Array.from(packTrailer)
3403
+ .map(b => b.toString(16).padStart(2, '0'))
3404
+ .join('');
3405
+ if (packTrailerSha !== expectedShaFromIndex) {
3406
+ throw new InternalError(
3407
+ `Packfile trailer mismatch: expected ${expectedShaFromIndex}, got ${packTrailerSha}. The packfile may be corrupted.`
3408
+ )
3409
+ }
3410
+
3411
+ // 2. Deep Integrity Check: Calculate actual SHA-1 of packfile payload
3412
+ // This ensures true data integrity by verifying the entire packfile content
3413
+ // Use subarray for zero-copy reading of large files
3414
+ const payload = pack.subarray(0, -20);
3415
+ const actualPayloadSha = await shasum(payload);
3416
+ if (actualPayloadSha !== expectedShaFromIndex) {
3417
+ throw new InternalError(
3418
+ `Packfile payload corrupted: calculated ${actualPayloadSha} but expected ${expectedShaFromIndex}. The packfile may have been tampered with.`
3419
+ )
3420
+ }
3421
+
3422
+ // Mark as verified to prevent performance regression on subsequent reads
3423
+ p._checksumVerified = true;
3424
+ }
3425
+
3392
3426
  const result = await p.read({ oid, getExternalRefDelta });
3393
3427
  result.format = 'content';
3394
3428
  result.source = `objects/pack/${filename.replace(/idx$/, 'pack')}`;
@@ -5161,7 +5195,7 @@ function assertParameter(name, value) {
5161
5195
  /**
5162
5196
  * discoverGitdir
5163
5197
  *
5164
- * When processing git commands on a submodule determine
5198
+ * When processing git commands on a submodule or worktree, determine
5165
5199
  * the actual git directory based on the contents of the .git file.
5166
5200
  *
5167
5201
  * Otherwise (if sent a directory) return that directory as-is.
@@ -5178,6 +5212,11 @@ function assertParameter(name, value) {
5178
5212
  *
5179
5213
  */
5180
5214
 
5215
+ // Check if a path is absolute (Unix / or Windows drive letter like C:\ or C:/)
5216
+ function isAbsolute(filepath) {
5217
+ return filepath.startsWith('/') || /^[a-zA-Z]:[\\/]/.test(filepath)
5218
+ }
5219
+
5181
5220
  async function discoverGitdir({ fsp, dotgit }) {
5182
5221
  assertParameter('fsp', fsp);
5183
5222
  assertParameter('dotgit', dotgit);
@@ -5192,6 +5231,10 @@ async function discoverGitdir({ fsp, dotgit }) {
5192
5231
  ._readFile(dotgit, 'utf8')
5193
5232
  .then(contents => contents.trimRight().substr(8))
5194
5233
  .then(submoduleGitdir => {
5234
+ // Worktrees use absolute gitdir paths; submodules use relative ones.
5235
+ if (isAbsolute(submoduleGitdir)) {
5236
+ return submoduleGitdir
5237
+ }
5195
5238
  const gitdir = join(dirname(dotgit), submoduleGitdir);
5196
5239
  return gitdir
5197
5240
  })
@@ -9255,8 +9298,8 @@ function filterCapabilities(server, client) {
9255
9298
 
9256
9299
  const pkg = {
9257
9300
  name: 'isomorphic-git',
9258
- version: '1.37.1',
9259
- agent: 'git/isomorphic-git@1.37.1',
9301
+ version: '1.37.3',
9302
+ agent: 'git/isomorphic-git@1.37.3',
9260
9303
  };
9261
9304
 
9262
9305
  class FIFO {