-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
buffer: make buflen in integer range
#51821
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
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
This comment was marked as outdated.
This comment was marked as outdated.
d51e680 to
f2c4e6f
Compare
buflen in integer range
250acee to
2e93994
Compare
2e93994 to
a21b523
Compare
This comment was marked as outdated.
This comment was marked as outdated.
|
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
This comment was marked as outdated.
This comment was marked as outdated.
Commit Queue failed- Loading data for nodejs/node/pull/51821 ✔ Done loading data for nodejs/node/pull/51821 ----------------------------------- PR info ------------------------------------ Title buffer: make `buflen` in integer range (#51821) ⚠ Could not retrieve the email or name of the PR author's from user's GitHub profile! Branch kylo5aby:buffer-utf8value -> nodejs:main Labels buffer, c++, semver-major, author ready, needs-ci Commits 1 - buffer: make `buflen` in integer range Committers 1 - Antoine du Hamel <[email protected]> PR-URL: https://github.com/nodejs/node/pull/51821 Fixes: https://github.com/nodejs/node/issues/51817 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: James M Snell <[email protected]> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/51821 Fixes: https://github.com/nodejs/node/issues/51817 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: James M Snell <[email protected]> -------------------------------------------------------------------------------- ⚠ Commits were pushed since the last approving review: ⚠ - buffer: make `buflen` in integer range ℹ This PR was created on Wed, 21 Feb 2024 09:45:39 GMT ✔ Approvals: 2 ✔ - Joyee Cheung (@joyeecheung) (TSC): https://github.com/nodejs/node/pull/51821#pullrequestreview-2080749937 ✔ - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/51821#pullrequestreview-2281595354 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2025-02-23T16:54:25Z: https://ci.nodejs.org/job/node-test-pull-request/65394/ - Querying data for job/node-test-pull-request/65394/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/13856744953 |
|
Landed in 1ba4732 |
make
buflenwithin the integer range whenbuffer.toString()and writing a string to buffer(for examplebuffer.write(str))Fixes: #51817