Repository navigation
buffer: validate end argument of indexOf methods - #66590
Open
gengjiawen wants to merge 1 commit into
Open
gengjiawen wants to merge 1 commit into
gengjiawen wants to merge 1 commit into
Conversation
Buffer.prototype.indexOf(), lastIndexOf() and includes() passed any
`end` that was neither a string nor undefined straight to the binding,
which CHECKs that it is a number, so values such as `null` or `{}`
aborted the process. Numbers that do not fit in an int64 (`Infinity`,
`1e20`) went through an undefined double-to-int64 conversion and made
the search return -1 on x64.
Throw ERR_INVALID_ARG_TYPE for non-number values and clamp numbers to
[0, buffer.byteLength] before calling into the binding.
Fixes: nodejs#66589
Refs: nodejs#62390
Signed-off-by: Jiawen Geng <technicalcute@gmail.com>
Assisted-by: claude:opus-5.5
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #66590 +/- ##
==========================================
- Coverage 90.45% 90.43% -0.02%
==========================================
Files 791 791
Lines 276562 276572 +10
Branches 53111 53116 +5
==========================================
- Hits 250154 250131 -23
- Misses 16801 16841 +40
+ Partials 9607 9600 -7
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Buffer.prototype.indexOf(),lastIndexOf()andincludes()pass anyendthat is neither a string norundefinedstraight to the binding, which CHECKs that it is a number, sobuf.indexOf('a', 0, null)aborts the process. Numbers that do not fit in an int64 (Infinity,1e20) go through an undefined double-to-int64 conversion and the search returns -1 on x64.This validates
endwithvalidateNumber()inbidirectionalIndexOf()and clamps it to[0, buffer.byteLength]before it reaches C++:ERR_INVALID_ARG_TYPEinstead of abortingInfinityand other values past the end search the whole bufferNaNand-Infinityselect an empty range (they already returned -1 before)Fixes: #66589
Refs: #62390
AI disclosure: written with the help of Claude (claude:opus-5.5). I checked the bug against the source and the latest nightly, and reviewed the fix and tests.