GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||
GeezerVison is showing github.com — buffer: stop clamping indexOf byteOffset to int32 by vedchaudhari · Pull Request #67009 · nodejs/node Conversation
Contributor
On buffers bigger than 2 GiB, const G = 2 ** 30; const buf = Buffer.alloc(3 * G); buf[2.25 * G] = 0x0a; buf[2.75 * G] = 0x0a; buf.indexOf(0x0a, 2.5 * G); // main: 2415919104 (before the offset), this PR: 2952790016 buf.includes(0x0a, 2.9 * G); // main: true, this PR: false buf.lastIndexOf(0x0a, 2.6 * G); // main: -1, this PR: 2415919104 The int32 limit was added in 2016 (6c1e5ad), when buffers couldn't be bigger than 2 GiB. The new cases in Tested on macOS arm64. Note: #66590 edits the same comment, so whichever lands second will need a small rebase. Fixes: #67008 Assisted-by: Claude. I reproduced the bug, reviewed the change and ran the tests myself.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsbidirectionalIndexOf() clamped byteOffset to the int32 range, so on buffers larger than 2 GiB an offset above 2 ** 31 - 1 started the search at 2 ** 31 - 1 instead. indexOf() and includes() could then match before the requested offset, and lastIndexOf() missed matches. Offsets below -(2 ** 31) were clamped the same way. The binding already takes an int64 offset, so clamp to the safe integer range instead. This still keeps Infinity and other values that int64 can't represent from reaching the binding. Fixes: nodejs#67008 Refs: nodejs#66325 Assisted-by: claude:opus-5.5 Signed-off-by: vedchaudhari <[email protected]>
|
There was an error while loading. Please reload this page.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@ ## main #67009 +/- ## ========================================== - Coverage 92.96% 90.66% -2.30% ========================================== Files 428 797 +369 Lines 195232 278262 +83030 Branches 30184 53512 +23328 ========================================== + Hits 181492 252286 +70794 - Misses 13413 16340 +2927 - Partials 327 9636 +9309
🚀 New features to boost your workflow:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@addaleax since you reviewed #66325, would you have a moment to take a look at this one? It's the other half of #67008. Offsets past 2 GiB still get clamped to int32, so indexOf(), lastIndexOf() and includes() search from the wrong spot. Thanks! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@ronag since you added the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Landed in 924250d |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
bidirectionalIndexOf() clamped byteOffset to the int32 range, so on buffers larger than 2 GiB an offset above 2 ** 31 - 1 started the search at 2 ** 31 - 1 instead. indexOf() and includes() could then match before the requested offset, and lastIndexOf() missed matches. Offsets below -(2 ** 31) were clamped the same way. The binding already takes an int64 offset, so clamp to the safe integer range instead. This still keeps Infinity and other values that int64 can't represent from reaching the binding. Fixes: #67008 Refs: #66325 Assisted-by: claude:opus-5.5 Signed-off-by: vedchaudhari <[email protected]> PR-URL: #67009 Reviewed-By: Robert Nagy <[email protected]>
bidirectionalIndexOf() clamped byteOffset to the int32 range, so on buffers larger than 2 GiB an offset above 2 ** 31 - 1 started the search at 2 ** 31 - 1 instead. indexOf() and includes() could then match before the requested offset, and lastIndexOf() missed matches. Offsets below -(2 ** 31) were clamped the same way. The binding already takes an int64 offset, so clamp to the safe integer range instead. This still keeps Infinity and other values that int64 can't represent from reaching the binding. Fixes: nodejs#67008 Refs: nodejs#66325 Assisted-by: claude:opus-5.5 Signed-off-by: vedchaudhari <[email protected]> PR-URL: nodejs#67009 Reviewed-By: Robert Nagy <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
buffer: indexOf/includes clamp byteOffset to 2^31-1 and return a negative index on buffers over 2 GiB
There was an error while loading. Please reload this page.