diff options
author | Trevor Norris <trev.norris@gmail.com> | 2013-05-20 14:37:55 -0700 |
---|---|---|
committer | Trevor Norris <trev.norris@gmail.com> | 2013-05-20 15:23:23 -0700 |
commit | 2cad7a69ce3228b1e40f3bf8117ca739a5d6929d (patch) | |
tree | 1aeeb2eb5483fbda2eeb76013794a687b4da243b /lib | |
parent | 3a2b5030ae1cd200e92eaf3928bd20a8deda50c6 (diff) | |
download | android-node-v8-2cad7a69ce3228b1e40f3bf8117ca739a5d6929d.tar.gz android-node-v8-2cad7a69ce3228b1e40f3bf8117ca739a5d6929d.tar.bz2 android-node-v8-2cad7a69ce3228b1e40f3bf8117ca739a5d6929d.zip |
buffer: throw when writing beyond buffer
Previously one could write anywhere in a buffer pool if they accidently
got their offset wrong. Mainly because the cc level checks only test
against the parent slow buffer and not against the js object properties.
So now we check to make sure values won't go beyond bounds without
letting the dev know.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/buffer.js | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/buffer.js b/lib/buffer.js index c75dbc93a8..000c54b3a8 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -339,6 +339,9 @@ Buffer.prototype.write = function(string, offset, length, encoding) { } encoding = String(encoding || 'utf8').toLowerCase(); + if (string.length > 0 && (length < 0 || offset < 0)) + throw new RangeError('attempt to write beyond buffer bounds'); + var ret; switch (encoding) { case 'hex': |