Skip to content

Fix crash in forEachProperty when Proxy getPrototypeOf trap throws - #29344

Closed
robobun wants to merge 1 commit into
mainfrom
farm/d64af4ab/fix-foreach-property-proxy-getprototype
Closed

robobun wants to merge 1 commit into
mainfrom
farm/d64af4ab/fix-foreach-property-proxy-getprototype

Conversation

@robobun

@robobun robobun commented Apr 15, 2026

Copy link
Copy Markdown
Collaborator

Inspecting an object whose prototype chain contains a Proxy with a throwing getPrototypeOf trap would crash with a null pointer dereference.

const obj = {};
const proto = new Proxy({}, {
  getPrototypeOf() { throw new Error("trap"); }
});
Object.setPrototypeOf(obj, proto);
console.log(obj); // segfault

In JSC__JSValue__forEachPropertyImpl, when walking the prototype chain on the slow path, getPrototype() can throw and return an empty JSValue. Calling .getObject() on an empty value dereferences a null JSCell.

The fast path in the same function already handles this case by checking the return value and clearing the exception. This applies the same handling to the slow path.

Found by Fuzzilli.

When walking the prototype chain in JSC__JSValue__forEachPropertyImpl,
getPrototype() can throw (e.g. from a Proxy getPrototypeOf trap) and
return an empty JSValue. Calling .getObject() on that empty value
dereferences a null JSCell.

Handle the empty value and clear the exception, matching how the fast
path in the same function already handles this case.
@robobun

robobun commented Apr 15, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 7:41 AM PT - Apr 15th, 2026

❌ @robobun, your commit c23b18a has 3 failures in Build #45809 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 29344

That installs a local version of the PR into your bun-29344 executable, so you can run:

bun-29344 --bun

@github-actions

Copy link
Copy Markdown
Contributor

This PR may be a duplicate of:

  1. Fix null deref in forEachProperty when prototype is a Proxy #28325 - Fixes same null deref in forEachProperty when prototype is a Proxy
  2. fix: clear exception before continue in property enumeration slow path #28530 - Clears exception before continue in property enumeration slow path (same root cause)
  3. Fix crash in forEachProperty when prototype chain contains a Proxy #28854 - Fixes same crash in forEachProperty when prototype chain contains a Proxy
  4. Fix null deref in forEachProperty when Proxy prototype throws #28882 - Fixes same null deref in forEachProperty when Proxy prototype throws
  5. Handle exception from getPrototype in forEachProperty #28918 - Handles exception from getPrototype in forEachProperty (same fix area)
  6. Fix use-after-poison in forEachProperty prototype chain walk #28919 - Fixes use-after-poison in forEachProperty prototype chain walk (same root cause)
  7. fix null deref in forEachProperty prototype walk #28991 - Fixes same null deref in forEachProperty prototype walk
  8. Fix null deref in Bun.inspect when Proxy getPrototypeOf throws #29071 - Fixes same null deref in Bun.inspect when Proxy getPrototypeOf throws

🤖 Generated with Claude Code

@robobun

robobun commented Apr 15, 2026

Copy link
Copy Markdown
Collaborator Author

Duplicate of #28325 (and several others). Closing in favor of the earliest open PR.

@robobun robobun closed this Apr 15, 2026
@robobun
robobun deleted the farm/d64af4ab/fix-foreach-property-proxy-getprototype branch April 15, 2026 12:15
@coderabbitai

coderabbitai Bot commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

Pull request was closed or merged during review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 78d07d6b-e882-43b6-8f1f-e4a178737990

📥 Commits

Reviewing files that changed from the base of the PR and between 443ba81 and c23b18a.

📒 Files selected for processing (2)
  • src/bun.js/bindings/bindings.cpp
  • test/js/bun/util/inspect.test.js

Walkthrough

Modified prototype-chain traversal in bindings to handle exceptions from Proxy getPrototype traps and explicitly manage non-object prototype results. Extended test fixtures to verify crash safety when prototype retrieval fails.

Changes

Cohort / File(s) Summary
Prototype Traversal Logic
src/bun.js/bindings/bindings.cpp
Updated JSC__JSValue__forEachPropertyImpl to store prototype results in intermediate variable, clear exceptions from Proxy traps via CLEAR_IF_EXCEPTION, and safely handle null/non-object prototype values instead of unconditionally invoking .getObject().
Test Coverage
test/js/bun/util/inspect.test.js
Added crash-testing fixture with object whose prototype is a Proxy that throws on getPrototypeOf introspection, expanding coverage for safe prototype-chain inspection paths in Bun.inspect().
🚥 Pre-merge checks | ✅ 1 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description provides a concrete crash example, explains the root cause, and describes the fix, but does not follow the required template structure with 'What does this PR do?' and 'How did you verify your code works?' sections. Reorganize the description to follow the required template sections: add a 'What does this PR do?' section and a 'How did you verify your code works?' section documenting test coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the bug fix: preventing crashes when a Proxy's getPrototypeOf trap throws during prototype chain iteration.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — straightforward null-check fix matching the existing fast-path pattern, with a regression test.

Extended reasoning...

Overview

The PR modifies in (slow path prototype-chain walk) and adds a crash-reproduction test to .

The Fix

The slow path was calling in a single expression. If the Proxy trap throws, returns an empty ; calling on an empty value dereferences a null , causing a segfault.

The fix splits the call, clears any pending exception with , and guards behind a truthiness check — exactly the same pattern already used on the fast path (and in two other nearby calls in the same function).

Security Risks

None. The fix makes exception handling more defensive; it cannot introduce new attack surface.

Level of Scrutiny

Low. This is a one-liner logic fix with a clear root cause, an obvious correct fix, a pre-existing identical pattern to follow, and a test. The changed code is in the inspect/property-enumeration path, not in auth, crypto, or IPC.

Other Factors

No bugs were found by the automated system. The test suite fixture pattern is consistent with how other crash-regression tests are written in the same file. The commit has already landed on (c23b18a).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant