← WebKit — 2026-W37

5d1761dffb0059dae2de405ab872b7bbd2798576  [JSC] Extract `CheckInBounds` from `StringAt` and `StringCodePointAt`

severity medium class OOB-read confidence 0.45 signal score 11.84 Source/JavaScriptCore/dfg
Primitive: String.prototype.at/codePointAt DFG nodes lacked SSA-phase bounds-check lowering that StringCharCodeAt had.
Triage note: SSALoweringPhase now runs lowerStringBoundsCheck for StringAt and StringCodePointAt, and FTL adds a boundsCheckLowered fast path plus gating the OutOfBounds speculation on !isInBounds(). FTL still retained its own aboveOrEqual slow path, so this largely consolidates/optimizes bounds handling for the newer nodes rather than demonstrably removing a reachable OOB.
Structural signals: checked_int (+5.39), null_guard (+1.95), msg_strong (+3.0), msg_medium (+2.0), area:Source/JavaScriptCore/dfg (+2.5)

Commit message

[JSC] Extract `CheckInBounds` from `StringAt` and `StringCodePointAt`
https://bugs.webkit.org/show_bug.cgi?id=323640

Reviewed by Yusuke Suzuki.

StringAt and StringCodePointAt speculate that the index is in bounds, and
the abstract interpreter types their result on the strength of that check,
so a user such as `string.codePointAt(index) === undefined` folds to a
constant. The node then has no users left, and MovHintRemoval + DCE in the
FTL pipeline remove it together with its bounds check, so out-of-bounds
indices keep returning the folded constant without exiting.

Extract the bounds check into a CheckInBounds node in SSA lowering, as
existing implementation for StringCharCodeAt. The check survives DCE on its own,
while an unused node stays removable. StringAt with an in-bounds array mode
now checks the index before it is normalized, so a negative index exits
with OutOfBounds and the next compile picks the out-of-bounds mode, which
handles negative indices inline without exiting.

Test: JSTests/stress/string-index-must-generate-dce.js

* JSTests/stress/string-index-dce-bounds-check.js: Added.
(shouldBe):
(codePointAtIsUndefined):
(atIsUndefined):
(charCodeAtIsNaN):
(atNegative):
* Source/JavaScriptCore/dfg/DFGSSALoweringPhase.cpp:
(JSC::DFG::SSALoweringPhase::handleNode):
* Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp:
(JSC::FTL::DFG::LowerDFGToB3::compileStringCharAtImpl):
(JSC::FTL::DFG::LowerDFGToB3::compileStringCodePointAt):

Canonical link: https://commits.webkit.org/321014@main

Before / after

Loading diff…