diff options
author | Ćukasz Walukiewicz <lukasz@walukiewicz.eu> | 2013-04-05 16:48:18 +0200 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-04-08 16:17:38 -0700 |
commit | 2e28832660099b49d861f4d4039d8d35ebb6c77e (patch) | |
tree | 8a5d9a7ed4ab8016807f1df89a7686148647a7c0 /test | |
parent | c93af860a079654becb3b1d06184ab7428dedffb (diff) | |
download | node-new-2e28832660099b49d861f4d4039d8d35ebb6c77e.tar.gz |
buffer: fix offset checks
Fixed offset checks in Buffer.readInt32LE() and Buffer.readInt32BE()
functions.
Diffstat (limited to 'test')
-rw-r--r-- | test/simple/test-buffer.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/simple/test-buffer.js b/test/simple/test-buffer.js index b0ab6ed53c..cd9096de5c 100644 --- a/test/simple/test-buffer.js +++ b/test/simple/test-buffer.js @@ -908,6 +908,39 @@ assert.throws(function() { buf.writeFloatLE(0.0, -1); }, /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. assert.throws(function() { |