Repository navigation
[VM] Validate toFixed receivers before coercing fractionDigits - #2308
Open
ZainnQureshii wants to merge 1 commit into
Open
ZainnQureshii wants to merge 1 commit into
ZainnQureshii wants to merge 1 commit into
Conversation
Number.prototype.toFixed coerced and range-checked fractionDigits before checking its receiver, so an invalid receiver could run user valueOf code or throw RangeError before the TypeError the spec requires (thisNumberValue is step 1). Move the receiver check first, matching toExponential and toPrecision. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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
Before this change,
Number.prototype.toFixedcoerces and range-checksfractionDigitsbefore validating its receiver inlib/VM/JSLib/Number.cpp:399. Invalid receivers can therefore run user code and throwErrororRangeErrorbefore the requiredTypeError.Move the existing receiver check from its old position at
lib/VM/JSLib/Number.cpp:417to:401, before argument coercion atlib/VM/JSLib/Number.cpp:414, matching ECMAScript §21.1.3.3. The regression attest/hermes/number-tofixed-receiver.js:35changes fromreceiver 0 Error true RangeErrortoreceiver 0 TypeError false TypeError, with the same result for eight invalid receivers. Primitive and boxed Number controls still print1.25 1.This fixes the handwritten implementation only. The generated snapshots
API/hermes_sandbox/external/hermes_sandbox_impl_dbg_compiled_5.c:202384andAPI/hermes_sandbox/external/hermes_sandbox_impl_opt_compiled_5.c:106173remain unchanged and retain argument-first validation until regeneration, whichAPI/hermes_sandbox/README.md:5permits periodically.Test Plan
ASan Debug build on macOS. Paths below use
buildfor the out-of-tree CMake directory andlit-*for its sibling test output directories.With the C++ fix reverted and the new test kept:
After restoring the fix and rebuilding:
The build printed Apple linker warnings about deprecated and ignored
-no_pie.utils/tidy.sh(clang-tidy), fullcheck-hermes, release/JIT builds and sandbox execution were not run.Prepared with AI assistance (Claude Code) and reviewed with GitHub Copilot.
🤖 Generated with Claude Code