diff --git a/lib/encoding/bufferreader.js b/lib/encoding/bufferreader.js index a730a61..73f351d 100644 --- a/lib/encoding/bufferreader.js +++ b/lib/encoding/bufferreader.js @@ -91,8 +91,16 @@ BufferReader.prototype.readUInt64BEBN = function() { }; BufferReader.prototype.readUInt64LEBN = function() { - var data = Array.prototype.slice.call(this.buf, this.pos, this.pos + 8); - var bn = new BN(data, 10, 'le'); + var second = this.buf.readUInt32LE(this.pos); + var first = this.buf.readUInt32LE(this.pos + 4); + var combined = (first * 0x100000000) + second; + var bn; + if (combined <= 0x1fffffffffffff) { + bn = new BN(combined); + } else { + var data = Array.prototype.slice.call(this.buf, this.pos, this.pos + 8); + bn = new BN(data, 10, 'le'); + } this.pos = this.pos + 8; return bn; };