GeezerVison is showing github.com — crypto: remove kMaxLength on randomBytes() · nodejs/node@944f680
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/node_crypto.cc +7-3Lines changed: 7 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4869,9 +4869,13 @@ void RandomBytes(const FunctionCallbackInfo<Value>& args) { |
4869 | 4869 | return env->ThrowTypeError("size must be a number >= 0"); |
4870 | 4870 | } |
4871 | 4871 |
|
4872 | | - const uint32_t size = args[0]->Uint32Value(); |
4873 | | - if (size > Buffer::kMaxLength) { |
4874 | | - return env->ThrowTypeError("size > Buffer::kMaxLength"); |
| 4872 | + const int64_t size = args[0]->IntegerValue(); |
| 4873 | + if (using_old_buffer) { |
| 4874 | + if (size > Buffer::kMaxLength) |
| 4875 | + return env->ThrowTypeError("size > Buffer::kMaxLength"); |
| 4876 | + } else { |
| 4877 | + if (!IsValidSmi(size)) |
| 4878 | + return env->ThrowRangeError("size is not a valid Smi"); |
4875 | 4879 | } |
4876 | 4880 |
|
4877 | 4881 | Local<Object> obj = Object::New(env->isolate()); |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-crypto-random.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -53,5 +53,5 @@ function checkCall(cb, desc) { |
53 | 53 | // #5126, "FATAL ERROR: v8::Object::SetIndexedPropertiesToExternalArrayData() |
54 | 54 | // length exceeds max acceptable value" |
55 | 55 | assert.throws(function() { |
56 | | - crypto.randomBytes(0x3fffffff + 1); |
| 56 | + crypto.randomBytes((-1 >>> 0) + 1); |
57 | 57 | }, TypeError); |