Repository navigation
Fix ES2024 TypedArray accepting almost every kind of key - #2264
Open
alielmorsy wants to merge 1 commit into
Open
alielmorsy wants to merge 1 commit into
alielmorsy wants to merge 1 commit into
Conversation
…rings, Floats,...etc. by intercepting the non-index canonical keys and ignoring writes to them. Specifically: - Reject [[DefineOwnProperty]] for out-of-bounds or non-index canonical keys (throws TypeError via Object.defineProperty, returns false via Reflect.defineProperty). - Silently ignore writes (returns true) while still performing value conversion when the receiver is the TypedArray itself.
alielmorsy
force-pushed
the
fix/typedarray-invalid-index-set
branch
from
October 22, 2026 20:18
1abc2c1 to
239e01e
Compare
This branch has not been deployed
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.
Summary
Fix ES2024 TypedArray accepting almost every kind of key including strings, Floats,...etc. by intercepting the non-index canonical keys and ignoring writes to them.
A TypedArray handles every canonical numeric string key itself (ES2024 10.4.5, CanonicalNumericIndexString). Hermes treated keys such as
"-1","-0","1.5","4294967295","NaN"and"Infinity"as ordinary property names, because they are not array indices, so a write created a real own property on the TypedArray.Specifically:
Object.prototypecan no longer answert[-1]or"5" in t.Strings that only look numeric but are not canonical (
"01","+1","1e3") remain ordinary properties.Example
Object.keys(t)["0","1","-1","1.5","NaN"]["0","1"]["0","1"]t[-2],"-2" in tfrom proto trueundefined falseundefined falseObject.defineProperty(t, "-3", ...)TypeErrorTypeErrorDetailed Fix
Detecting the keys. Added two static helpers to implement CanonicalNumericIndexString (ES2024 7.1.21):
isCanonicalNumericKey(runtime, key)returns true for any Number key. For strings, it rounds through ToNumber andnumberToStringto see if the string survives unchanged. Handled"-0"as an edge case since ToString(-0) evaluates to"0".isNonIndexCanonicalNumericKey(runtime, key)ensures the key is not an array index. Because TypedArray lengths useuint32_t,0xFFFFFFFFcan never be a valid integer index. An overload forSymbolIDhandles pinning the string in aLocalsslot before delegating here.Both guards start with
vmisa<JSTypedArrayBase>, so non-TypedArray objects only pay for a cell-kind check without parsing strings.[[Set]] (ES2024 10.4.5.5). In
putComputedWithReceiver_RJSandputNamedWithReceiver_RJS, we now bail out before prototype lookup if the target is a TypedArray and the key is a non-index canonical numeric string. ThesetInvalidTypedArrayIndexhelper returns true without writing. If the receiver is the TypedArray itself, it triggerssetOwnIndexed(self, 0xFFFFFFFF, value). Since this index is always out of bounds, it simply executes the standard ToNumber/ToBigInt element conversion (preservingvalueOfside effects and BigInt TypeErrors) without modifying the buffer.[[DefineOwnProperty]] (ES2024 10.4.5.3).
defineOwnPropertyInternalnow rejects non-index canonical keys on TypedArrays right before adding a named property.defineOwnComputedPrimitive, if an index key is missing (detached buffer or out of bounds), define now properly fails. Previously, value definitions fell back intosetOwnIndexedand were silently dropped, while accessor definitions accidentally created named properties.[[Get]] / [[HasProperty]] (ES2024 10.4.5.4, 10.4.5.2). Lookups on prototype chains now halt at a TypedArray for numeric keys:
getComputedPrimitiveDescriptor, if an own lookup misses on a TypedArray, any canonical numeric key stops the traversal (propObj = nullptr). Lookups liket[5]past the array bound will no longer pull values off the prototype.getNamedDescriptorUnsafeapplies the same rule for named lookups liket.NaNort.Infinity, both directly and when a TypedArray appears higher up the prototype chain.Because these paths are shared, operations like
in,Reflect.has, prototype accessors, and out-of-bounds writes avoid hitting prototype setters without needing separate guards.Test Plan
Added
regress-typedarray-canonical-numeric-keys.jsand ran tests on (WSL ubuntu 22) and Windows MSVC 2022