buffer: fix offset checks
Fixed offset checks in Buffer.readInt32LE() and Buffer.readInt32BE() functions.
This commit is contained in:
parent
c93af860a0
commit
2e28832660
@ -737,14 +737,14 @@ function readInt32(buffer, offset, isBigEndian) {
|
|||||||
|
|
||||||
Buffer.prototype.readInt32LE = function(offset, noAssert) {
|
Buffer.prototype.readInt32LE = function(offset, noAssert) {
|
||||||
if (!noAssert)
|
if (!noAssert)
|
||||||
checkOffset(offset, 2, this.length);
|
checkOffset(offset, 4, this.length);
|
||||||
return readInt32(this, offset, false);
|
return readInt32(this, offset, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Buffer.prototype.readInt32BE = function(offset, noAssert) {
|
Buffer.prototype.readInt32BE = function(offset, noAssert) {
|
||||||
if (!noAssert)
|
if (!noAssert)
|
||||||
checkOffset(offset, 2, this.length);
|
checkOffset(offset, 4, this.length);
|
||||||
return readInt32(this, offset, true);
|
return readInt32(this, offset, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -908,6 +908,39 @@ assert.throws(function() {
|
|||||||
buf.writeFloatLE(0.0, -1);
|
buf.writeFloatLE(0.0, -1);
|
||||||
}, /offset is not uint/);
|
}, /offset is not uint/);
|
||||||
|
|
||||||
|
// offset checks
|
||||||
|
var buf = new Buffer(0);
|
||||||
|
|
||||||
|
assert.throws(function() { buf.readUInt8(0); }, /beyond buffer length/);
|
||||||
|
assert.throws(function() { buf.readInt8(0); }, /beyond buffer length/);
|
||||||
|
|
||||||
|
[16, 32].forEach(function(bits) {
|
||||||
|
var buf = new Buffer(bits / 8 - 1);
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
function() { buf['readUInt' + bits + 'BE'](0); },
|
||||||
|
/beyond buffer length/,
|
||||||
|
'readUInt' + bits + 'BE'
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
function() { buf['readUInt' + bits + 'LE'](0); },
|
||||||
|
/beyond buffer length/,
|
||||||
|
'readUInt' + bits + 'LE'
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
function() { buf['readInt' + bits + 'BE'](0); },
|
||||||
|
/beyond buffer length/,
|
||||||
|
'readInt' + bits + 'BE()'
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
function() { buf['readInt' + bits + 'LE'](0); },
|
||||||
|
/beyond buffer length/,
|
||||||
|
'readInt' + bits + 'LE()'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
// SlowBuffer sanity checks.
|
// SlowBuffer sanity checks.
|
||||||
assert.throws(function() {
|
assert.throws(function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user