From 5fe1f6b2e1d5a179a05b95b9f5067eb584778b7a Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Tue, 3 Nov 2020 13:28:20 -1000 Subject: [PATCH] handle offset flooring consistently --- index.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index f56bcbd..b14acc3 100644 --- a/index.js +++ b/index.js @@ -1198,7 +1198,8 @@ Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { this[offset + 3]) } -Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE (offset = 0) { +Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE (offset) { + offset = offset >>> 0 validateNumber(offset, 'offset') const first = this[offset] const last = this[offset + 7] @@ -1219,7 +1220,8 @@ Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE ( return BigInt(lo) + (BigInt(hi) << 32n) }) -Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE (offset = 0) { +Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE (offset) { + offset = offset >>> 0 validateNumber(offset, 'offset') const first = this[offset] const last = this[offset + 7] @@ -1317,7 +1319,8 @@ Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { (this[offset + 3]) } -Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE (offset = 0) { +Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE (offset) { + offset = offset >>> 0 validateNumber(offset, 'offset') const first = this[offset] const last = this[offset + 7] @@ -1337,7 +1340,8 @@ Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE (of this[++offset] * 2 ** 24) }) -Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE (offset = 0) { +Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE (offset) { + offset = offset >>> 0 validateNumber(offset, 'offset') const first = this[offset] const last = this[offset + 7] -- 2.34.1