-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
buffer: make buflen
in integer range
#51821
base: main
Are you sure you want to change the base?
Conversation
3833a0f
to
d51e680
Compare
src/node_buffer.cc
Outdated
if (max_length > static_cast<size_t>(v8::String::kMaxLength)) | ||
ThrowErrStringTooLong(env->isolate()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (max_length > static_cast<size_t>(v8::String::kMaxLength)) | |
ThrowErrStringTooLong(env->isolate()); | |
if (max_length > static_cast<size_t>(v8::String::kMaxLength)) { | |
ThrowErrStringTooLong(env->isolate()); | |
return; | |
} |
You're missing a return here; the Throw* functions don't actually return, you have to do it manually.
test/parallel/test-buffer-alloc.js
Outdated
// Invalid length of Buffer.utf8Write | ||
{ | ||
const ubuf = Buffer.allocUnsafeSlow(2 ** 32); | ||
assert.throws(() => { | ||
ubuf.utf8Write('a', 2, kStringMaxLength + 2); | ||
}, stringTooLongError); | ||
} | ||
|
||
// Invalid length of Buffer.write | ||
{ | ||
const ubuf = Buffer.allocUnsafeSlow(2 ** 32); | ||
assert.throws(() => { | ||
ubuf.write('a', 2, kStringMaxLength + 2); | ||
}, stringTooLongError); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test probably won't work in test/parallel
, since 2 GiB is a lot to allocate (maybe it'll work on Linux)? It might work to put it in test/sequential
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @kvakil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For tests that require a lot of resource, we typically use test/pummel
. You could also catch ERR_MEMORY_ALLOCATION_FAILED
in the buffer creation and common.skip()
in the test if the memory could not be allocated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks your suggestion @joyeecheung , I have update it, add a method in StringBytes
to ensure that the capacity of buffer remains within the integer range when operating with string
d51e680
to
f2c4e6f
Compare
buflen
in integer range
250acee
to
2e93994
Compare
2e93994
to
a21b523
Compare
this PR has been approved but hasn't been landed for a long time, could you please take a look? @legendecas |
5b60d83
to
69cee50
Compare
69cee50
to
748299e
Compare
I find some test checks didn't pass, I believe that's because in the test file, the buffer with size > INT32_MAX on x32 platform which will throw range error, I have updated and skip the test file on x32 platform, could you take a look? @legendecas |
This needs a rebase. |
748299e
to
49e5825
Compare
Resolved. Thanks! |
This will need a rebase again 😞 |
49e5825
to
30a5969
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #51821 +/- ##
==========================================
+ Coverage 87.32% 87.34% +0.01%
==========================================
Files 649 650 +1
Lines 182570 182847 +277
Branches 35026 35071 +45
==========================================
+ Hits 159432 159701 +269
- Misses 16406 16411 +5
- Partials 6732 6735 +3
|
30a5969
to
db80e6e
Compare
make
buflen
within the integer range whenbuffer.toString()
and writing a string to buffer(for examplebuffer.write(str)
)Fixes: #51817