Skip to content

Conversation

@kylo5aby
Copy link
Contributor

@kylo5aby kylo5aby commented Feb 21, 2024

make buflen within the integer range when buffer.toString() and writing a string to buffer(for example buffer.write(str))

Fixes: #51817

@nodejs-github-bot nodejs-github-bot added buffer Issues and PRs related to the buffer subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Feb 21, 2024
@kylo5aby kylo5aby force-pushed the buffer-utf8value branch 3 times, most recently from 3833a0f to d51e680 Compare February 22, 2024 05:06
Comment on lines 727 to 728
if (max_length > static_cast<size_t>(v8::String::kMaxLength))
ThrowErrStringTooLong(env->isolate());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Comment on lines 1158 to 1173
// 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);
}

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @kvakil

Copy link
Member

@joyeecheung joyeecheung Feb 22, 2024

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.

Copy link
Contributor Author

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

@kvakil kvakil added semver-major PRs that contain breaking changes and should be released in the next major version. request-ci Add this label to start a Jenkins CI on a PR. labels Feb 22, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 22, 2024
@nodejs-github-bot

This comment was marked as outdated.

@kylo5aby kylo5aby changed the title buffer: fix Buffer.utf8Write fails when length exceeds integer range buffer: make ·buflen` in integer range Feb 22, 2024
@kylo5aby kylo5aby changed the title buffer: make ·buflen` in integer range buffer: make buflen in integer range Feb 22, 2024
@kylo5aby kylo5aby force-pushed the buffer-utf8value branch 3 times, most recently from 250acee to 2e93994 Compare February 23, 2024 05:48
@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Mar 1, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 1, 2024
@nodejs-github-bot

This comment was marked as outdated.

@kylo5aby
Copy link
Contributor Author

this PR has been approved but hasn't been landed for a long time, could you please take a look? @legendecas

@kylo5aby kylo5aby force-pushed the buffer-utf8value branch 2 times, most recently from 5b60d83 to 69cee50 Compare March 27, 2024 02:29
@legendecas legendecas added the request-ci Add this label to start a Jenkins CI on a PR. label Mar 27, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 27, 2024
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 added the commit-queue Add this label to land a pull request using GitHub Actions. label Mar 14, 2025
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Mar 14, 2025
@nodejs-github-bot
Copy link
Collaborator

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/.ncu
https://github.com/nodejs/node/actions/runs/13856744953

@jasnell
Copy link
Member

jasnell commented Mar 14, 2025

Landed in 1ba4732

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. buffer Issues and PRs related to the buffer subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-failed An error occurred while landing this pull request using GitHub Actions. needs-ci PRs that need a full CI run. semver-major PRs that contain breaking changes and should be released in the next major version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Buffer.utf8Write() fails to write when buffer length exceeds 2 GB

10 participants