-
Notifications
You must be signed in to change notification settings - Fork 5k
fix(inspect): don't keep enumerating properties with an exception pending #37330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 nit: The same
->getPrototype(globalObject).getObject()pattern remains atsrc/jsc/bindings/napi.cpp:2072(innapi_get_all_property_names's filter loop, with no exception check aftergetOwnPropertyDescriptor) — a Proxy prototype whose trap throws produces the same segfault-at-0x5. It's the sole greppable sibling of this pattern insrc/; pre-existing N-API code so non-blocking, but per REVIEW.md's "grep for every sibling site" it may be worth including the one-line fix here or noting it's intentionally out of scope.Extended reasoning...
What this is
This PR fixes
iterating->getPrototype(globalObject).getObject()inJSC__JSValue__forEachPropertyImpl(bindings.cpp:5675-5680) — whenProxyObject::getPrototypethrows, it returns an emptyJSValue, and calling.getObject()on an empty JSValue dereferences a null cell pointer and segfaults at address 0x5. A grep for this exact pattern acrosssrc/finds one remaining instance atsrc/jsc/bindings/napi.cpp:2072, insidenapi_get_all_property_names:Code path that triggers it
Reachable via
napi_get_all_property_names(env, obj, napi_key_include_prototypes, napi_key_enumerable | ..., ...)on an object with a Proxy in its prototype chain. The filter loop at napi.cpp:2061-2080 runs whenkey_filterincludes any ofnapi_key_enumerable/writable/configurableandkey_mode == napi_key_include_prototypes. Inside that loop,getOwnPropertyDescriptor(line 2071) invokes the Proxy'sgetOwnPropertyDescriptortrap; if the trap throws, there is no exception check before line 2072, soowner->getPrototype(globalObject)on the same Proxy hitsRETURN_IF_EXCEPTIONinsideProxyObject::performGetPrototypeand returns{}. A statefulgetPrototypeOftrap that succeeds duringgetPropertyNames(line 1999) but throws when re-called here produces the same empty return.Why the existing code doesn't prevent it
The
if (!proto) break;on line 2073 checks the result of.getObject(), but.getObject()itself is what crashes: on JSVALUE64 an empty JSValue encodes as 0, which satisfiesisCell(), soasCell()returnsnullptrandJSCell::getObject()readsm_typeat offset ~5 → SIGSEGV at 0x5. This is the identical mechanism the PR description documents for the release-build segfault inforEachPropertyImpl.Step-by-step proof
napi_get_all_property_names(env, obj, napi_key_include_prototypes, napi_key_enumerable, napi_key_numbers_to_strings, &result)whereobj's prototype isnew Proxy({}, { ownKeys: () => ['x'], getOwnPropertyDescriptor() { throw new Error('boom'); } }).getPropertyNamesat line 1999 collects'x'via theownKeystrap (usesjsc_key_mode = Include, so it does not callgetOwnPropertyDescriptor);NAPI_RETURN_IF_EXCEPTIONat 2057 passes.propKey = 'x';owner = object;object->getOwnPropertyDescriptor(...)returns false (not own), so thewhilebody runs andownerbecomes the Proxy.owner->getOwnPropertyDescriptor(globalObject, 'x', desc)invokes the Proxy trap, which throws. Return value is false → loop body runs again with the exception still pending.owner->getPrototype(globalObject)on the Proxy entersProxyObject::performGetPrototype, hitsRETURN_IF_EXCEPTION, returnsJSValue().JSValue().getObject()→asCell()=nullptr→nullptr->isObject()reads offset 5 → segfault.Impact and fix
This is pre-existing N-API code the PR does not touch, only reachable through a native addon calling
napi_get_all_property_nameson an object with an adversarial Proxy in its chain, so it should not block this PR — merging is strictly an improvement over main. Flagging per REVIEW.md's "Fix the whole class in the same PR — grep for every sibling site sharing the pattern... If a site is intentionally excluded, say so in the PR" since this is the sole greppable sibling of the exact pattern being fixed. The fix is the same shape as this PR's hunk: capturegetPrototype(globalObject)into aJSValue, check/clear the exception, break if empty, then call.getObject()— plus an exception check aftergetOwnPropertyDescriptor.