isomorphic-git 1.44.7 → 1.44.9

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.
@@ -1196,7 +1196,8 @@ function SecondsNanoseconds(
1196
1196
  milliseconds = date.valueOf();
1197
1197
  }
1198
1198
  const seconds = Math.floor(milliseconds / 1000);
1199
- const nanoseconds = (milliseconds - seconds * 1000) * 1000000;
1199
+ // Match the integer precision used when these timestamps are written to the index.
1200
+ const nanoseconds = Math.floor((milliseconds - seconds * 1000) * 1000000);
1200
1201
  return [seconds, nanoseconds]
1201
1202
  }
1202
1203
 
@@ -1617,7 +1618,9 @@ function compareStats(entry, stats, filemode = true, trustino = true) {
1617
1618
  const staleness =
1618
1619
  (filemode && e.mode !== s.mode) ||
1619
1620
  e.mtimeSeconds !== s.mtimeSeconds ||
1621
+ e.mtimeNanoseconds !== s.mtimeNanoseconds ||
1620
1622
  e.ctimeSeconds !== s.ctimeSeconds ||
1623
+ e.ctimeNanoseconds !== s.ctimeNanoseconds ||
1621
1624
  e.uid !== s.uid ||
1622
1625
  e.gid !== s.gid ||
1623
1626
  (trustino && e.ino !== s.ino) ||
@@ -3001,13 +3004,25 @@ class GitPktLine {
3001
3004
  const reader = new StreamReader(stream);
3002
3005
  return async function read() {
3003
3006
  try {
3004
- let length = await reader.read(4);
3005
- if (length == null) return true
3006
- length = parseInt(length.toString('utf8'), 16);
3007
+ const header = await reader.read(4);
3008
+ if (header == null || header.length === 0) return true
3009
+ const hex = header.toString('utf8');
3010
+ if (!/^[0-9a-fA-F]{4}$/.test(hex)) {
3011
+ throw new ParseError('four hexadecimal digits', hex)
3012
+ }
3013
+ const length = parseInt(hex, 16);
3007
3014
  if (length === 0) return null
3008
3015
  if (length === 1) return null // delim packets
3016
+ if (length < 4) {
3017
+ throw new ParseError('pkt-line length of 0, 1, or at least 4', hex)
3018
+ }
3009
3019
  const buffer = await reader.read(length - 4);
3010
- if (buffer == null) return true
3020
+ if (buffer == null || buffer.length !== length - 4) {
3021
+ throw new ParseError(
3022
+ `${length - 4} bytes of pkt-line data`,
3023
+ `${buffer == null ? 0 : buffer.length} bytes`
3024
+ )
3025
+ }
3011
3026
  return buffer
3012
3027
  } catch (err) {
3013
3028
  stream.error = err;
@@ -3656,12 +3671,16 @@ ${obj.gpgsig ? obj.gpgsig : ''}`
3656
3671
  }
3657
3672
  }
3658
3673
  const obj = {};
3674
+ const seen = new Set();
3659
3675
  for (const h of hs) {
3660
3676
  const key = h.slice(0, h.indexOf(' '));
3661
3677
  const value = h.slice(h.indexOf(' ') + 1);
3662
- if (Array.isArray(obj[key])) {
3663
- obj[key].push(value);
3664
- } else {
3678
+ // A tag header may appear only once, so the first occurrence wins, the
3679
+ // way canonical git reads them. Keeping the last one instead would make a
3680
+ // tag with a duplicate `object` header point at a different target here
3681
+ // than in git, under the same oid.
3682
+ if (!seen.has(key)) {
3683
+ seen.add(key);
3665
3684
  obj[key] = value;
3666
3685
  }
3667
3686
  }
@@ -3792,12 +3811,18 @@ class GitCommit {
3792
3811
  const obj = {
3793
3812
  parent: [],
3794
3813
  };
3814
+ const seen = new Set();
3795
3815
  for (const h of hs) {
3796
3816
  const key = h.slice(0, h.indexOf(' '));
3797
3817
  const value = h.slice(h.indexOf(' ') + 1);
3798
3818
  if (Array.isArray(obj[key])) {
3799
3819
  obj[key].push(value);
3800
- } else {
3820
+ } else if (!seen.has(key)) {
3821
+ // Only `parent` may appear more than once. For every other header the
3822
+ // first occurrence wins, the way canonical git reads them. Keeping the
3823
+ // last one instead would make a commit with a duplicate `tree` header
3824
+ // resolve to a different tree here than in git, under the same oid.
3825
+ seen.add(key);
3801
3826
  obj[key] = value;
3802
3827
  }
3803
3828
  }
package/managers/index.js CHANGED
@@ -1189,7 +1189,8 @@ function SecondsNanoseconds(
1189
1189
  milliseconds = date.valueOf();
1190
1190
  }
1191
1191
  const seconds = Math.floor(milliseconds / 1000);
1192
- const nanoseconds = (milliseconds - seconds * 1000) * 1000000;
1192
+ // Match the integer precision used when these timestamps are written to the index.
1193
+ const nanoseconds = Math.floor((milliseconds - seconds * 1000) * 1000000);
1193
1194
  return [seconds, nanoseconds]
1194
1195
  }
1195
1196
 
@@ -1610,7 +1611,9 @@ function compareStats(entry, stats, filemode = true, trustino = true) {
1610
1611
  const staleness =
1611
1612
  (filemode && e.mode !== s.mode) ||
1612
1613
  e.mtimeSeconds !== s.mtimeSeconds ||
1614
+ e.mtimeNanoseconds !== s.mtimeNanoseconds ||
1613
1615
  e.ctimeSeconds !== s.ctimeSeconds ||
1616
+ e.ctimeNanoseconds !== s.ctimeNanoseconds ||
1614
1617
  e.uid !== s.uid ||
1615
1618
  e.gid !== s.gid ||
1616
1619
  (trustino && e.ino !== s.ino) ||
@@ -2994,13 +2997,25 @@ class GitPktLine {
2994
2997
  const reader = new StreamReader(stream);
2995
2998
  return async function read() {
2996
2999
  try {
2997
- let length = await reader.read(4);
2998
- if (length == null) return true
2999
- length = parseInt(length.toString('utf8'), 16);
3000
+ const header = await reader.read(4);
3001
+ if (header == null || header.length === 0) return true
3002
+ const hex = header.toString('utf8');
3003
+ if (!/^[0-9a-fA-F]{4}$/.test(hex)) {
3004
+ throw new ParseError('four hexadecimal digits', hex)
3005
+ }
3006
+ const length = parseInt(hex, 16);
3000
3007
  if (length === 0) return null
3001
3008
  if (length === 1) return null // delim packets
3009
+ if (length < 4) {
3010
+ throw new ParseError('pkt-line length of 0, 1, or at least 4', hex)
3011
+ }
3002
3012
  const buffer = await reader.read(length - 4);
3003
- if (buffer == null) return true
3013
+ if (buffer == null || buffer.length !== length - 4) {
3014
+ throw new ParseError(
3015
+ `${length - 4} bytes of pkt-line data`,
3016
+ `${buffer == null ? 0 : buffer.length} bytes`
3017
+ )
3018
+ }
3004
3019
  return buffer
3005
3020
  } catch (err) {
3006
3021
  stream.error = err;
@@ -3649,12 +3664,16 @@ ${obj.gpgsig ? obj.gpgsig : ''}`
3649
3664
  }
3650
3665
  }
3651
3666
  const obj = {};
3667
+ const seen = new Set();
3652
3668
  for (const h of hs) {
3653
3669
  const key = h.slice(0, h.indexOf(' '));
3654
3670
  const value = h.slice(h.indexOf(' ') + 1);
3655
- if (Array.isArray(obj[key])) {
3656
- obj[key].push(value);
3657
- } else {
3671
+ // A tag header may appear only once, so the first occurrence wins, the
3672
+ // way canonical git reads them. Keeping the last one instead would make a
3673
+ // tag with a duplicate `object` header point at a different target here
3674
+ // than in git, under the same oid.
3675
+ if (!seen.has(key)) {
3676
+ seen.add(key);
3658
3677
  obj[key] = value;
3659
3678
  }
3660
3679
  }
@@ -3785,12 +3804,18 @@ class GitCommit {
3785
3804
  const obj = {
3786
3805
  parent: [],
3787
3806
  };
3807
+ const seen = new Set();
3788
3808
  for (const h of hs) {
3789
3809
  const key = h.slice(0, h.indexOf(' '));
3790
3810
  const value = h.slice(h.indexOf(' ') + 1);
3791
3811
  if (Array.isArray(obj[key])) {
3792
3812
  obj[key].push(value);
3793
- } else {
3813
+ } else if (!seen.has(key)) {
3814
+ // Only `parent` may appear more than once. For every other header the
3815
+ // first occurrence wins, the way canonical git reads them. Keeping the
3816
+ // last one instead would make a commit with a duplicate `tree` header
3817
+ // resolve to a different tree here than in git, under the same oid.
3818
+ seen.add(key);
3794
3819
  obj[key] = value;
3795
3820
  }
3796
3821
  }