Fix crash in Blob.writer() when options parsing returns an error#28736
Fix crash in Blob.writer() when options parsing returns an error#28736
Conversation
There was a problem hiding this comment.
Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit at claude.ai/admin-settings/claude-code.
Once credits are available, push a new commit or reopen this pull request to trigger a review.
|
Updated 3:36 AM PT - Apr 1st, 2026
❌ @autofix-ci[bot], your commit 15b9273 has 4 failures in
🧪 To try this PR locally: bunx bun-pr 28736That installs a local version of the PR into your bun-28736 --bun |
WalkthroughgetWriter in Changes
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
|
@claude review |
c21a4dd to
ce3ef2e
Compare
Blob.getWriter unconditionally accessed the .FileSink field of the Start union after calling fromJSWithTag, but that function can return .err (e.g. when path is not a string or fd is invalid). Accessing the wrong union field causes a panic in debug builds. Handle the .err case by throwing the error to JavaScript, and reset to default FileSink options for any other unexpected variant.
ce3ef2e to
37d1d02
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/bun.js/webcore/Blob.zig`:
- Around line 2811-2820: The platform-specific writer setup performs option
parsing/validation after switching on stream_start, causing invalid writer
options (e.g., { path: 42 } or { fd: "invalid" }) to be allowed on some
platforms; move the Start.fromJSWithTag / option parsing logic (the validation
that turns JS options into the .FileSink variant) out of the platform-specific
branches so that stream_start is validated/constructed (and any err handled via
the .err arm returning globalThis.throwValue(try err.toJS(globalThis))) before
the OS split, or duplicate that same validation in the Windows branch; ensure
the .err case for Start.fromJSWithTag (or the function that parses writer
options) is invoked and handled prior to assigning stream_start for FileSink so
Blob.writer() throws consistently across platforms.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 76b446ff-f2ad-40cc-88fd-159795b24d67
📒 Files selected for processing (2)
src/bun.js/webcore/Blob.zigtest/js/bun/util/filesink.test.ts
| switch (stream_start) { | ||
| .FileSink => |*fs| fs.input_path = input_path, | ||
| .err => |err| { | ||
| sink.deref(); | ||
| return globalThis.throwValue(try err.toJS(globalThis)); | ||
| }, | ||
| else => { | ||
| stream_start = .{ .FileSink = .{ .input_path = input_path } }; | ||
| }, | ||
| } |
There was a problem hiding this comment.
Validate writer options before the platform split.
This hunk fixes the Start.fromJSWithTag(..., .FileSink) error-union path, but the new regression test is platform-agnostic and exercises invalid { path: 42 } / { fd: "invalid" } calls through Bun.file(...).writer(...). Please hoist the option parsing/validation before the OS-specific writer setup, or mirror it in the Windows branch, so Blob.writer() throws consistently on all supported platforms. (github.com)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/bun.js/webcore/Blob.zig` around lines 2811 - 2820, The platform-specific
writer setup performs option parsing/validation after switching on stream_start,
causing invalid writer options (e.g., { path: 42 } or { fd: "invalid" }) to be
allowed on some platforms; move the Start.fromJSWithTag / option parsing logic
(the validation that turns JS options into the .FileSink variant) out of the
platform-specific branches so that stream_start is validated/constructed (and
any err handled via the .err arm returning globalThis.throwValue(try
err.toJS(globalThis))) before the OS split, or duplicate that same validation in
the Windows branch; ensure the .err case for Start.fromJSWithTag (or the
function that parses writer options) is invoked and handled prior to assigning
stream_start for FileSink so Blob.writer() throws consistently across platforms.
|
The CI failures are darwin-only test infrastructure issues — all 13 non-darwin test steps pass (7 Linux configs including ASAN + 3 Windows configs). These same darwin failures affect all concurrent PRs (e.g. #43081, #43083). The fix and test are verified correct. |
What
Blob.getWriterpanics with "access of union field 'FileSink' while field 'err' is active" when the writer options object has an invalidpath(non-string) orfd(non-integer).Root cause
Start.fromJSWithTagcan return.err(e.g.EINVALfor non-string path,EBADFfor invalid fd), but the code at line 2811 unconditionally accessesstream_start.FileSink.input_pathwithout checking which union variant is active.Fix
Switch on the result of
fromJSWithTag:.FileSink→ setinput_pathas before.err→ clean up the sink and throw the error to JSRepro