Skip to content

Commit

Permalink
fix: prevent infinite loop when metering BigInt values
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Oct 29, 2020
1 parent 7867597 commit 3b76f82
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions packages/transform-metering/src/meter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { ceil } = Math;
const ObjectConstructor = Object;

// eslint-disable-next-line no-bitwise
const bigIntWord = typeof BigInt !== 'undefined' && BigInt(1 << 32);
const bigIntWord = typeof BigInt !== 'undefined' && BigInt(2) ** BigInt(64);
const bigIntZero = bigIntWord && BigInt(0);

// Stop deducting when we reach a negative number.
Expand Down Expand Up @@ -99,7 +99,6 @@ export function makeAllocateMeter(maybeAbort, meter, allocateCounter = null) {
remaining = -remaining;
}
while (remaining > bigIntZero) {
meter[c.METER_COMPUTE](undefined, throwForever);
remaining /= bigIntWord;
cost += 1;
}
Expand Down

0 comments on commit 3b76f82

Please sign in to comment.