[JSC] Fix undefined behavior in double-to-int conversions#66220
Merged
webkit-commit-queue merged 1 commit intoJun 2, 2026
Merged
Conversation
Collaborator
|
EWS run on current version of this PR (hash fc6e2a8) Details |
Constellation
approved these changes
Jun 2, 2026
https://bugs.webkit.org/show_bug.cgi?id=316051 Reviewed by Yusuke Suzuki. Several call sites convert unbounded, caller-controlled doubles to narrow integer types with a plain cast, which is undefined behavior when the truncated value is not representable ([conv.fpint]). With inputs reachable from JS (e.g. parseInt("80000000", 16), (1.5).toExponential(Infinity), String.fromCodePoint(-1), o[2 ** 32]), every conversion fixed here trips UBSan's float-cast-overflow check. This is not purely theoretical: in Bun, this UB caused user-observable bugs, e.g. parseInt("80000000", 16) returning a negative int32. Make the conversions defined via truncateDoubleToInt32() / truncateDoubleToUint32() / clampTo<unsigned>(), or by range-checking the double before narrowing. No behavior change on current WebKit toolchains. Tests: JSTests/stress/get-by-val-double-subscript-out-of-uint32-range.js JSTests/stress/jsonp-large-array-index.js JSTests/stress/number-tostring-methods-out-of-range-arguments.js JSTests/stress/parseint-large-result-int32-boxing.js JSTests/stress/string-from-code-point-out-of-range.js * JSTests/stress/get-by-val-double-subscript-out-of-uint32-range.js: Added. (shouldBe): (get put): * JSTests/stress/jsonp-large-array-index.js: Added. (shouldBe): * JSTests/stress/number-tostring-methods-out-of-range-arguments.js: Added. (shouldBe): * JSTests/stress/parseint-large-result-int32-boxing.js: Added. (shouldBe): (parseIntNoRadix): * JSTests/stress/string-from-code-point-out-of-range.js: Added. (shouldBe): * Source/JavaScriptCore/dfg/DFGOperations.cpp: (JSC::DFG::parseIntResult): * Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp: (Inspector::JSInjectedScriptHost::weakMapEntries): (Inspector::JSInjectedScriptHost::weakSetEntries): (Inspector::JSInjectedScriptHost::iteratorEntries): * Source/JavaScriptCore/runtime/JSCJSValue.h: (JSC::JSValue::getUInt32 const): * Source/JavaScriptCore/runtime/LiteralParser.cpp: (JSC::requires): * Source/JavaScriptCore/runtime/NumberPrototype.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * Source/JavaScriptCore/runtime/StringConstructor.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): Canonical link: https://commits.webkit.org/314356@main
fc6e2a8 to
3825a1a
Compare
Collaborator
|
Committed 314356@main (3825a1a): https://commits.webkit.org/314356@main Reviewed commits have been landed. Closing PR #66220 and removing active labels. |
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.
🛠 🧪 merge
3825a1a
fc6e2a8
🧪 win-tests🧪 ios-wk2-wpt🛠 jsc-armv7🧪 jsc-armv7-tests