diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2012-03-09 06:35:50 -0800 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2012-03-09 23:57:03 +0100 |
commit | 8c02f9b7c844909cf5977d065b793c99eb0f9c45 (patch) | |
tree | 502f4d08b899802c99ae30b07ffc945f7ee71b74 /src/node_buffer.cc | |
parent | 2589d5561191ac58f5c87efa796457c9936de73f (diff) | |
download | android-node-v8-8c02f9b7c844909cf5977d065b793c99eb0f9c45.tar.gz android-node-v8-8c02f9b7c844909cf5977d065b793c99eb0f9c45.tar.bz2 android-node-v8-8c02f9b7c844909cf5977d065b793c99eb0f9c45.zip |
buffer: throw from constructor if length > kMaxLength
Throw, don't abort. `new Buffer(0x3fffffff + 1)` used to bring down the process
with the following error message:
FATAL ERROR: v8::Object::SetIndexedPropertiesToExternalArrayData() length
exceeds max acceptable value
Fixes #2280.
Diffstat (limited to 'src/node_buffer.cc')
-rw-r--r-- | src/node_buffer.cc | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 14aa3ef612..12fe1e0962 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -171,13 +171,14 @@ Handle<Value> Buffer::New(const Arguments &args) { HandleScope scope; - if (args[0]->IsInt32()) { - // var buffer = new Buffer(1024); - size_t length = args[0]->Uint32Value(); - new Buffer(args.This(), length); - } else { - return ThrowException(Exception::TypeError(String::New("Bad argument"))); + if (!args[0]->IsUint32()) return ThrowTypeError("Bad argument"); + + size_t length = args[0]->Uint32Value(); + if (length > Buffer::kMaxLength) { + return ThrowRangeError("length > kMaxLength"); } + new Buffer(args.This(), length); + return args.This(); } |