Skip to content

Refuse an S3-backed Blob at spawn stdin, in the shell, in Bun.build files and in redis - #46673

Closed
robobun wants to merge 4 commits into
mainfrom
robobun/954c364a/s3-blob-sync-consumers
Closed

robobun wants to merge 4 commits into
mainfrom
robobun/954c364a/s3-blob-sync-consumers

Conversation

@robobun

@robobun robobun commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Related to #43931

Problem

  • An S3-backed Blob is read as empty at four sites: spawn stdin, a $ redirect, Bun.build files and redis arguments. There is no request and no error.
  • Where stdin is a pipe (off Linux, and in the shell), stdin never closes and the call never ends.
  • The guard needs_to_read_file() (src/jsc/webcore_types.rs:402) names only a file-backed Blob. Found by fuzzing: no user report.

Fix

  • BlobExt::in_memory_view() and the $ tag match the store kinds exhaustively. Stdio::extract_blob, the $ tag and BlobOrStringOrBuffer::from_js throw for an S3-backed Blob.
  • For stdin, extract_blob goes by the bytes, not the size field. A Blob emptied by new Response([blob]) no longer leaves stdin open.
  • Correct: an S3 object has no path or fd for the child. WebSocket.send (WebSocket: real closing handshake, one failure path, ws rewritten on native transports (consolidates the open WebSocket PRs) #45223) throws for the same input.
  • Verified: spawn-empty-arrayBufferOrBlob.test.ts, bunshell-file.test.ts, bundler_files.test.ts and buffer-operations.test.ts fail on 1.4.3. Also ran spawn.test.ts, bunshell.test.ts and bindgen. Self-reviewed: 9 concerns raised, 9 addressed.

Background

  • A Blob views a store: memory, a file, or an S3 key. Only memory has bytes at once. Stdio::extract_blob makes a Blob a child's stdin.
  • BlobOrStringOrBuffer::from_js parses Bun.build files and redis arguments. Its opt-out FileBlobs::Allow had one user, redis, and is deleted.
  • Considered || is_s3() at each guard: a fourth store kind passes them. Considered streaming into stdin: a failed GET exits 0.

Downsides

  • These now throw: echo hi < ${s3file} (printed hi), s3file.slice(0, 0) as stdin (was empty), redis.set(key, Bun.file(p)) (stored "").
  • An in-memory Blob stdin costs 69 to 82 instructions in extract_blob. .text: +256 bytes. No new allocation or syscall.
  • Still read as empty: socket.write(s3file), import() of an S3File blob: URL, new Blob(["x", s3file]) (Blob: read file-backed parts in multi-part new Blob([...]) #33600).
Notes

Origin. Found by fuzzing. No user reported these sites. #43931 described the class and was closed as not a user report. The only user reports in the class, #25851 and #28459, are about sites that this PR does not change.

Repro. A loopback Bun.serve stands in for S3 and counts requests. Linux x64.

const log = [];
const srv = Bun.serve({ port: 0, hostname: "127.0.0.1", fetch(q) { log.push(q.method); return new Response("0123456789"); } });
const s3 = new Bun.S3Client({ endpoint: srv.url.href, accessKeyId: "k", secretAccessKey: "s", bucket: "b" });
const p = Bun.spawn(["cat"], { stdin: s3.file("o"), stdout: "pipe" });
console.log(JSON.stringify(await p.stdout.text()), await p.exited, log); // main: "" 0 []
Input main This PR
Bun.spawn / Bun.spawnSync stdin or stdio[0]: an S3File, Bun.file("s3://..."), a slice, new Blob([s3file]), a Request body, new Response([s3file]) child reads "", exit 0, 0 requests. With BUN_FEATURE_FLAG_DISABLE_MEMFD=1 (the path of macOS and Windows) the call never ends TypeError (ERR_INVALID_ARG_TYPE), 0 requests
$`cat < ${s3file}`, $`wc -c < ${s3file}` never ends the tag throws before a command runs
$`echo hi < ${s3file}` prints hi the tag throws
$`echo hi > ${s3file}` throws when the command runs (Cannot redirect stdout/stderr to an immutable blob) the tag throws the S3 text, which names Bun.write for this direction
$`cat < ${new Response([s3file])}` never ends cat as an external command: TypeError from spawn when the command starts. A builtin that reads stdin still gets "" (see below)
Bun.build({ files: { "/entry.js": s3file } }) builds an empty module TypeError: File blob cannot be used here
redis.set(key, s3file), redis.set(key, Bun.file(path)) sends SET key "" TypeError: File blob cannot be used here, no command sent
stdin or <: a Blob emptied by new Response([blob]) never ends (spawn with memfd off, and the shell always) empty stdin, the command ends
stdin: await s3file.bytes(), < ${await s3file.bytes()} work work
stdout: s3file, stdio[3]: s3file existing TypeError texts unchanged
stdio[3]: a Blob emptied by new Response([blob]) TypeError: Blob cannot be used for stdio[3] yet unchanged (a new test pins it)
< ${Bun.file(fd)}, < ${Bun.file(path)} work unchanged (a new test pins the fd form)

Error texts.

  • spawn: An S3-backed Blob cannot be used as stdin. Pass await blob.bytes() instead (TypeError, ERR_INVALID_ARG_TYPE, like the other stdio refusals in extract_blob).
  • shell: An S3-backed Blob is not supported in a shell command yet. To redirect from it, pass its bytes: `< ${await blob.bytes()}`. To redirect to it, write the output of the command: `await Bun.write(blob, output)` (TypeError, ERR_INVALID_ARG_TYPE, the same name and code as the spawn refusal). The tag throws it before it can see the operator, so the text names both directions. A test runs both remedies against the S3 stand-in.
  • Bun.build files and redis: File blob cannot be used here (TypeError, ERR_INVALID_ARG_TYPE): the text that Bun.file already got in files, and that bindgen uses for both kinds.
  • The texts name await blob.bytes() and not blob.stream(): with a stream as stdin a failed GET is lost (the child reads "" and exits 0). That is handed off.

Why a throw and not a read. A file-backed Blob reaches the child as a path or an fd, and Bun never reads it. An S3 object has neither, and spawnSync cannot wait for a GET. Node also refuses when the call is made: a Blob in stdio throws ERR_INVALID_ARG_VALUE from spawn (v26.3.0).

Measurements. Release builds (--profile=release, ThinLTO) of main 6292c6539d and of that commit plus the commits of this PR, Linux x64. Instruction counts are gdb stepi from the first instruction of the function to its return, callees included, 3 runs each, every count repeated. The numbers are of the last commit (c200a79c58), except where a line names the first push.

Where the numbers that are not equal come from:

  • extract_blob (+13): one match on the store kind, the length of the view and the tests on it, where main loads the size field. The first push measured 88. The form with early returns that the review led to measures 82.
  • template string (+1): the prologue of handle_template_value spills depth (two stack moves) and runs one alignment nop less. No branch is added on that path.
  • .text (+256): extract_blob +94 bytes, handle_template_value +47, the parser -27 (from_js_maybe_file 849, now from_js 822), and section alignment.
  • The merge check used git merge-tree against the heads of the listed PRs. shell: reject a stream, used, failed or S3-backed Response body as stdin #42786 has a one-hunk conflict with this PR in docs/runtime/shell.mdx: both add a paragraph after the same list.

How the syscall and allocator numbers were taken: strace is not installed here, so gdb counted catch syscall stops (memfd_create, ftruncate, pwrite64, pipe2, close, socketpair) and breakpoint hits on mi_malloc, mi_zalloc, mi_realloc in the parent, for loops of 100 and 200 Bun.spawnSync({ cmd: ["true"], stdin: blob }). The numbers are the difference divided by 100.

The fourth-store-kind check: with a dummy variant added to store::Data, cargo check stops in bun_jsc (5 errors) and, with those patched, in bun_runtime (15 errors). Two of the 15 are new with this PR: in_memory_view (Blob.rs) and handle_template_value (shell_body.rs). That was run on the first shape of this PR. The two matches are unchanged since.

Sites that an S3-backed Blob still passes, with their trackers.

Adjacent, not changed. stdin: s3file.stream() works, but a failed GET is lost: the child reads "" and exits 0. It is the same for every ReadableStream stdin that errors. Handed off (#36236 had a fix).

Redis. #36836 made the same change for redis with its own text. This PR takes its test (a local listener that answers HELLO and records commands, no Redis server) and refuses in the shared parser, so #36836 can close.

Tests.

  • The new tests are in test/js/bun/spawn/spawn-empty-arrayBufferOrBlob.test.ts (13), test/js/bun/shell/bunshell-file.test.ts (3), test/bundler/bundler_files.test.ts (1) and test/js/valkey/unit/buffer-operations.test.ts (2).
  • With the released 1.4.3 (USE_SYSTEM_BUN=1): 10 of the 13 spawn tests fail (2 by timeout, because the child never ends), the shell S3 test fails and the moved-out Blob test times out, the bundler test fails, and 1 of the 2 redis tests fails. All pass with the change. The Bun.file(fd) redirect test, the three spawn controls and the in-memory redis test pass on both: they pin what must not change.
  • Three mutations of the first shape each failed a named test: size-based emptiness in extract_blob (the zero-size cases and both moved-out cases), and two that belonged to hunks that left this PR.
  • Full files with the change, debug build: spawn-empty-arrayBufferOrBlob.test.ts 23 pass, bunshell-file.test.ts 4 pass, bundler_files.test.ts 29 pass, buffer-operations.test.ts 2 pass (9 need Docker). bunshell.test.ts and spawn.test.ts ran twice each with the change. Each had one clean run and one run with a single timeout in a test that this PR does not touch: subshell > sharp installs from the npm registry, and stdout can be read took 2.5 s alone on that build (it passed alone 3 of 3). On the debug build of the later commits the same test takes 4.9 s to 5.0 s alone, at its 5 s limit. It uses stdin: "ignore" and stdout: "pipe", no Blob, and CI ran spawn.test.ts green on every lane for the first push.
  • Also green: test/internal/bindgen.test.ts, bun-cryptohasher.test.ts, websocket-blob.test.ts, bun-serve-static.test.ts, s3-moved-store.test.ts, spawnSync.test.ts, spawn-empty-arrayBufferOrBlob.test.ts, shell yield, file-io, throw, bunshell-file, test/integration/bun-types/bun-types.test.ts.
  • bun run rust:check-all: 12 targets ok (run on the first shape. The re-cut removed code and added none that is platform-specific).

After the review of the first push. Four things changed. A Blob that has a size and no bytes is refused at an extra slot again, as on main: the first push left stdio[3] closed with no error (one mutation run confirms the new test fails on that form). The shell refusal is a TypeError with ERR_INVALID_ARG_TYPE. Its text names the write remedy. The emptiness tests in extract_blob are two plain conditions. One thing did not change: spawn takes the body of a Request or Response before extract_blob refuses it, so bodyUsed is true after the S3 refusal. The two older refusals in that function do the same on 1.4.3, and #41812 is the open PR about when that body is taken.

Self-review. A review of the first shape asked for a re-cut. Done: the socket guard and the Response case left this PR (handed off), redis is in, the error texts name the value to pass, the docs do not list APIs as if the list were complete, and the tests got the zero-length slice, the s3:// spelling, a Bun.file(fd) control and a check that can see a stray request. Not done: the review also offered to write the two shared_view() roots as exhaustive matches. Other open PRs rewrite those lines, so this PR narrows its claim and leaves them.


[human-review] gate passed · iteration 0 · 14 files touched

fails on main (without fix)
ASAN without fix: 14 failed, 9 skipped
$ BUN_DEBUG_QUIET_LOGS=1 bun scripts/build.ts --profile=debug --quiet test "--reporter=junit" "--reporter-outfile=/tmp/pr_gate.xml" test/bundler/bundler_files.test.ts test/js/bun/shell/bunshell-file.test.ts test/js/bun/spawn/spawn-empty-arrayBufferOrBlob.test.ts test/js/valkey/unit/buffer-operations.test.ts
bun test v1.4.4 (367d939d9)

test/bundler/bundler_files.test.ts:
(pass) bundler files option > basic in-memory file bundling [216.79ms]
(pass) bundler files option > in-memory file with imports [68.76ms]
(pass) bundler files option > in-memory file with relative imports (same directory) [91.69ms]
(pass) bundler files option > in-memory file with relative imports (subdirectory) [62.24ms]
(pass) bundler files option > in-memory file with relative imports (parent directory) [64.87ms]
(pass) bundler files option > in-memory file with relative imports between multiple files [84.50ms]
(pass) bundler files option > in-memory file with nested imports [80.24ms]
(pass) bundler files option > in-memory file with TypeScript [62.54ms]
(pass) bundler files option > in-memory file with JSX [330.16ms]
(pass) bundler files option > in-memory file with Blob content [78.89ms]
(pass
... (truncated)

release without fix: 21 failed, 9 skipped
bun test v1.4.3-canary.1 (367d939d9)

test/bundler/bundler_files.test.ts:
(pass) bundler files option > basic in-memory file bundling [332.71ms]
(pass) bundler files option > in-memory file with imports [10.02ms]
(pass) bundler files option > in-memory file with relative imports (same directory) [5.29ms]
(pass) bundler files option > in-memory file with relative imports (subdirectory) [4.25ms]
(pass) bundler files option > in-memory file with relative imports (parent directory) [2.92ms]
(pass) bundler files option > in-memory file with relative imports between multiple files [5.32ms]
(pass) bundler files option > in-memory file with nested imports [4.44ms]
(pass) bundler files option > in-memory file with TypeScript [2.33ms]
(pass) bundler files option > in-memory file with JSX [23.58ms]
(pass) bundler files option > in-memory file with Blob content [4.29ms]
(pass) bundler files option > in-memory file with a file-backed Blob is rejected [2.26ms]
265 |           entrypoints: ["/entry.js"],
266 |           files: {
267 |             "/entry.js": content,
268 |           },
269 |         }),
270 |       ).toThrow(
              ^
error: expect(received).toThrow(expect
... (truncated)
passes on PR (with fix)
ASAN with fix: 9 skipped
$ BUN_DEBUG_QUIET_LOGS=1 bun scripts/build.ts --profile=debug --quiet test "--reporter=junit" "--reporter-outfile=/tmp/pr_gate.xml" test/bundler/bundler_files.test.ts test/js/bun/shell/bunshell-file.test.ts test/js/bun/spawn/spawn-empty-arrayBufferOrBlob.test.ts test/js/valkey/unit/buffer-operations.test.ts
rustup spent 8s installing the pinned toolchain (nightly-2026-09-15); it was missing or incomplete on this machine
bun test v1.4.4 (367d939d9)

test/bundler/bundler_files.test.ts:
(pass) bundler files option > basic in-memory file bundling [167.07ms]
(pass) bundler files option > in-memory file with imports [65.05ms]
(pass) bundler files option > in-memory file with relative imports (same directory) [54.73ms]
(pass) bundler files option > in-memory file with relative imports (subdirectory) [47.78ms]
(pass) bundler files option > in-memory file with relative imports (parent directory) [87.50ms]
(pass) bundler files option > in-memory file with relative imports between multiple files [64.48ms]
(pass) bundler files option > in-memory file with nested imports [57.10ms]
(pass) bundler files option > in-memory file with TypeScript [58.91ms]
(pass) bundler files option 
... (truncated)

release with fix: 9 skipped
$ bun scripts/build.ts --profile=release
[configured] bun-profile → bun (stripped)
  target       linux-x64-gnu
  build type   Release
  build dir    ./build/release
  revision     1b26951ce4
  features     lto, baseline

23 deps, 396 codegen, 1302 objects in 1912ms

ninja: Entering directory `/workspace/bun/build/release'
[1/4] fetch lolhtml
[lolhtml] up to date
[2/4] fetch rust-argon2
[rust-argon2] up to date
[2/4] cargo plan → /workspace/bun/build/release/rust-target/plan.json
282 units: 194 lib, 16 proc-macro (host), 27 custom-build (host), 23 run custom-build, 17 lib (host), 4 run custom-build (host), 1 rlib
[3/4] reconfigure
[1/1672] mkdir stamps
[2/1672] mkdir codegen
[3/1672] gen bake.{client,server,error}.js
-> bake.client.js, bake.server.js, bake.error.js
[4/1672] install /workspace/bun
bun install v1.4.3-canary.1 (367d939d9)

Checked 22 installs across 44 packages (no changes) [5.03s]
[5/1672] install /workspace/bun/packages/bun-error
bun install v1.4.3-canary.1 (367d939d9)

Checked 1 install across 2 packages (no changes) [214.00ms]
[6/1672] rustc unicode_ident 
[7/1672] rustc unicode_xid 
[8/1672] gen string-map defines_table
[9/1672] rustc heck 
[1
... (truncated)
diff hotspot
docs/runtime/child-process.mdx                     |   2 +
 docs/runtime/s3.mdx                                |   2 +
 docs/runtime/shell.mdx                             |  10 ++
 packages/bun-types/bun.d.ts                        |   7 +-
 src/runtime/api/bun/spawn/stdio.rs                 |  11 +-
 src/runtime/node.rs                                |   2 +-
 src/runtime/node/types.rs                          |  26 +----
 src/runtime/shell/shell_body.rs                    |  47 +++++---
 src/runtime/valkey_jsc/js_valkey_functions.rs      |   6 +-
 src/runtime/webcore/Blob.rs                        |  14 ++-
 test/bundler/bundler_files.test.ts                 |  43 +++++++
 test/js/bun/shell/bunshell-file.test.ts            |  81 +++++++++++++
 .../spawn/spawn-empty-arrayBufferOrBlob.test.ts    | 129 +++++++++++++++++++++
 test/js/valkey/unit/buffer-operations.test.ts      | 127 ++++++++++++++++++++
 14 files changed, 457 insertions(+), 50 deletions(-)

gate history · 1 passed · 0 rejected · iteration 0

evidence per changed file
file                                                     reads  edits  tests
docs/runtime/child-process.mdx                               0      0     27
docs/runtime/s3.mdx                                          0      0     27
docs/runtime/shell.mdx                                       0      0     27
packages/bun-types/bun.d.ts                                  0      0     27
src/runtime/api/bun/spawn/stdio.rs                           1      1     27
src/runtime/node.rs                                          0      0     27
src/runtime/node/types.rs                                    1      0     28
src/runtime/shell/shell_body.rs                              1      0     28
src/runtime/valkey_jsc/js_valkey_functions.rs                0      0     27
src/runtime/webcore/Blob.rs                                  2      2     27
test/bundler/bundler_files.test.ts                           1      1     17
test/js/bun/shell/bunshell-file.test.ts                      0      0      7
test/js/bun/spawn/spawn-empty-arrayBufferOrBlob.test.ts      0      0      7
test/js/valkey/unit/buffer-operations.test.ts                0      0     14

…iles and in redis

`Bun.spawn`, `Bun.spawnSync`, the Bun Shell, the `files` option of `Bun.build`
and `RedisClient` take the bytes of a Blob at once. The guard in front of that
read, `needs_to_read_file()`, names only a file-backed Blob, and redis let
both kinds through. An S3-backed Blob was read as empty: the child got an
empty stdin or a pipe that never closed, the shell never ended, the bundler
built an empty module, and redis stored "".

- `BlobExt::in_memory_view()` is one exhaustive match over the store kinds.
  `blob::Any` gets the same accessor.
- `Stdio::extract_blob` reads "nothing to write" from the in-memory view, not
  from the size field, and throws for an S3-backed Blob.
- The `$` tag throws for an S3-backed Blob before a command runs.
- `BlobOrStringOrBuffer::from_js` refuses a Blob that has no in-memory view,
  for every caller. `FileBlobs` had one `Allow` user, redis, and is gone.

Found by fuzzing. No user reported it.
@robobun

robobun commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 6:56 AM PT - Oct 24th, 2026

✅ @robobun, your commit c200a79c58a9f7e0e7cb9fef6484d2418cf23411 passed in Build #131934! 🎉


🧪   To try this PR locally:

bunx bun-pr 46673

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

bun-46673 --bun

@robobun

robobun commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator Author

Status

Reproduced on main 6292c6539d and on the released 1.4.3, Linux x64. A loopback Bun.serve stands in for S3 and counts requests.

const log = [];
const srv = Bun.serve({ port: 0, hostname: "127.0.0.1", fetch(q) { log.push(q.method); return new Response("0123456789"); } });
const s3 = new Bun.S3Client({ endpoint: srv.url.href, accessKeyId: "k", secretAccessKey: "s", bucket: "b" });
const p = Bun.spawn(["cat"], { stdin: s3.file("o"), stdout: "pipe" });
console.log(JSON.stringify(await p.stdout.text()), await p.exited, log); // "" 0 []
  • Bun.spawn and Bun.spawnSync with stdin: s3file: the child reads "" and exits 0. The server gets 0 requests.
  • The same call with BUN_FEATURE_FLAG_DISABLE_MEMFD=1 never ends. $`cat < ${s3file}` never ends.
  • Bun.build({ files: { "/entry.js": s3file } }) builds an empty module.
  • redis.set(key, s3file) sends SET key "" (seen with a local listener that records commands).

The new tests fail with the released 1.4.3 (USE_SYSTEM_BUN=1 bun test <file>) and pass with this change.

CI on c200a79c58 (build #131934): 179 of 181 jobs passed. The two darwin any x64 - test-bun jobs wait for an agent. Five test files failed once and passed on retry or alone. None is in code that this PR changes, and three of them are in test/flaky-tests.txt.

PR: #46673

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 5 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 1b26951 and c200a79.

Files selected for processing: 14
  • docs/runtime/child-process.mdx
  • docs/runtime/s3.mdx
  • docs/runtime/shell.mdx
  • packages/bun-types/bun.d.ts
  • src/runtime/api/bun/spawn/stdio.rs
  • src/runtime/node.rs
  • src/runtime/node/types.rs
  • src/runtime/shell/shell_body.rs
  • src/runtime/valkey_jsc/js_valkey_functions.rs
  • src/runtime/webcore/Blob.rs
  • test/bundler/bundler_files.test.ts
  • test/js/bun/shell/bunshell-file.test.ts
  • test/js/bun/spawn/spawn-empty-arrayBufferOrBlob.test.ts
  • test/js/valkey/unit/buffer-operations.test.ts

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 7d240c1 and 1b26951.

Files selected for processing: 14
  • docs/runtime/child-process.mdx
  • docs/runtime/s3.mdx
  • docs/runtime/shell.mdx
  • packages/bun-types/bun.d.ts
  • src/runtime/api/bun/spawn/stdio.rs
  • src/runtime/node.rs
  • src/runtime/node/types.rs
  • src/runtime/shell/shell_body.rs
  • src/runtime/valkey_jsc/js_valkey_functions.rs
  • src/runtime/webcore/Blob.rs
  • test/bundler/bundler_files.test.ts
  • test/js/bun/shell/bunshell-file.test.ts
  • test/js/bun/spawn/spawn-empty-arrayBufferOrBlob.test.ts
  • test/js/valkey/unit/buffer-operations.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

Walkthrough

The change distinguishes in-memory Blob data from file-backed and S3-backed data across argument conversion, spawn, and shell input handling. It rejects unsupported S3-backed inputs, documents passing loaded bytes instead, and adds coverage for these behaviors.

Changes

Blob input handling

Layer / File(s) Summary
In-memory Blob classification and argument conversion
src/runtime/webcore/Blob.rs, src/runtime/node/..., src/runtime/valkey_jsc/js_valkey_functions.rs, packages/bun-types/bun.d.ts, test/bundler/bundler_files.test.ts, test/js/valkey/unit/buffer-operations.test.ts
Blob and Any expose an in-memory view. Node and Valkey argument conversion rejects Blobs without one. Tests cover rejected build content and Valkey arguments, plus in-memory Blob bytes.
Spawn Blob input handling
src/runtime/api/bun/spawn/stdio.rs, packages/bun-types/bun.d.ts, docs/runtime/child-process.mdx, docs/runtime/s3.mdx, test/js/bun/spawn/spawn-empty-arrayBufferOrBlob.test.ts
Spawn preserves empty in-memory Blob handling and rejects S3-backed Blobs in unsupported stdio slots. Documentation and tests cover passing loaded bytes and handling Blobs whose bytes were moved.
Shell Blob redirection
src/runtime/shell/shell_body.rs, docs/runtime/shell.mdx, test/js/bun/shell/bunshell-file.test.ts
Shell retains file-backed path handling and adds an error for S3-backed Blob redirection. Documentation and tests cover loaded S3 bytes, file descriptors, and Blobs with moved bytes.

Suggested reviewers: jarred-sumner

Priority: Normal

Merge Risk: Minimal · up to 1b269

No concrete issue currently prevents merging; complete the normal build and test checks.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title names the main change: spawn stdin, shell redirects, Bun.build files, and Redis arguments now reject S3-backed Blobs. The changeset matches this scope. The title is long (88 characters) but …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The pull request description is complete and on topic. It explains the problem, the implementation, scope, downsides, affected APIs, and verification results. Although it does not use the template hea…
Full details: Title check

Explanation

The title names the main change: spawn stdin, shell redirects, Bun.build files, and Redis arguments now reject S3-backed Blobs. The changeset matches this scope. The title is long (88 characters) but specific and not vague.

Full details: Description check

Explanation

The pull request description is complete and on topic. It explains the problem, the implementation, scope, downsides, affected APIs, and verification results. Although it does not use the template headings exactly, it provides the information required by “What does this PR do?” and “How did you verify your code works?”.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@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.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Beyond the inline findings, I also checked the BlobExt::in_memory_view rewrite in src/runtime/webcore/Blob.rs against the old needs_to_read_file() || is_s3() guard (both are Data::File / Data::S3 store matches in src/jsc/webcore_types.rs:394-404), so it is behavior-preserving, and its two pre-existing callers (src/runtime/server/ServerWebSocket.rs:242 and src/runtime/webcore/Blob.rs:5585) already branch on None, so they are unaffected.

Extended reasoning...

The change adds S3-backed Blob refusals at spawn stdin, the shell template tag, BlobOrStringOrBuffer::from_js (Bun.build files and redis), rewrites in_memory_view as an exhaustive store match, and deletes the FileBlobs::Allow opt-out; no auth, crypto, or injection surface is touched beyond the pre-existing shell null-byte check, which is moved unchanged. Inline findings were posted on the stdio[3] moved-out-blob regression, the Request/Response S3 body remedy text, the missing error code on the shell throw, and the sibling sites still unguarded, so a human look is already signalled.

Comment thread src/runtime/api/bun/spawn/stdio.rs Resolved
Comment thread src/runtime/api/bun/spawn/stdio.rs Resolved
Comment thread src/runtime/shell/shell_body.rs Resolved
Comment thread src/runtime/node/types.rs Resolved
robobun added a commit that referenced this pull request Oct 24, 2026
…e(fd)`

`import()`, `require()` and `new Worker()` of a `blob:` URL made from an
S3File loaded an empty module. No request went to S3 and nothing threw.
The `blob:` arm of the module loader took every Blob that is not a file
for bytes in memory, and an S3-backed Blob has none. For a `Bun.file(fd)`
URL the loader opened `blob:<uuid>` in the working directory.

The arm now takes the bytes from `in_memory_view()`. An S3-backed Blob, or
a file-backed one with no path, is a TypeError with the code
`ERR_INVALID_ARG_TYPE`: `import()` rejects, `require()` throws and a
Worker gets an `error` event. The message says how to read the Blob first.

Found by a read of the code, not by a user report. The same class at
other consumers is #46673.
`Stdio::extract_blob` took a Blob whose bytes `new Response([blob])` moved
out for an empty Blob at every slot. At stdio[3] that left the slot closed
with no error, where main throws "Blob cannot be used for stdio[3] yet".
Stdin still ignores such a Blob. An extra slot now also needs a size of 0.

The `$` tag throws its S3 refusal as a TypeError with the code
ERR_INVALID_ARG_TYPE: the name and code of the refusal of the same Blob as
the stdin of Bun.spawn.
robobun added a commit that referenced this pull request Oct 24, 2026
`import()`, `require()` and `new Worker()` of a `blob:` URL made from an
S3File loaded an empty module. No request went to S3 and nothing threw.
The `blob:` arm of the module loader took every Blob that is not a file
for bytes in memory, and an S3-backed Blob has none. For a `Bun.file(fd)`
URL the loader opened `blob:<uuid>` in the working directory.

The arm now takes the bytes from `in_memory_view()`. An S3-backed Blob, or
a file-backed one with no path, is a TypeError with the code
`ERR_INVALID_ARG_TYPE`: `import()` rejects, `require()` throws and a
Worker gets an `error` event. The message says how to read the Blob first.

Found by a read of the code, not by a user report. The same class at
other consumers is #46673.
Comment thread src/runtime/api/bun/spawn/stdio.rs Resolved

@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.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Beyond the inline finding, I checked that the in_memory_view() rewrite in src/runtime/webcore/Blob.rs:2290 keeps the old needs_to_read_file() || is_s3() result for every store state (a storeless Blob still yields its shared view, only File/S3 yield None), and that the other synchronous consumers (ServerWebSocket.rs:242, Blob.rs:5586) already go through the same accessor, so they are consistent. One thing worth a look: the new Any::in_memory_view() at src/runtime/webcore/Blob.rs:6274 has no caller in src/ — it looks like it can be dropped from this PR.

Extended reasoning...

The second push reworked the stdio empty-blob shortcut to require i == 0 || fast_size() == 0 and routed the shell refusal through throw_invalid_arguments with the code pinned in bunshell-file.test.ts, which addresses two of the earlier inline threads; the consume-then-throw path for Request/Response bodies at stdio.rs:313-316 is unchanged. The semantic check of the Blob accessor rewrite found no regression, and the only new observation is an uncalled helper added in the same file.

Still open from earlier reviews (2):

  • Unresolved: 2 minor or pre-existing.

Comment thread src/runtime/shell/shell_body.rs Resolved
… refusal

`Stdio::extract_blob` takes a Blob for empty when it has no bytes and a
size of 0. After the extra-slot refusal, stdin goes by the view: an
S3-backed Blob throws, a Blob with no bytes is ignored, any other Blob is
written. The behavior is the same as before. The condition no longer needs
a paragraph to explain it.

The `$` tag cannot see whether an S3-backed Blob follows `<` or `>`. Its
refusal now also says how to write the output of a command to the object:
`await Bun.write(blob, output)`.
@robobun

robobun commented Oct 24, 2026

Copy link
Copy Markdown
Collaborator Author

On the note that Any::in_memory_view() has no caller: it has one, Stdio::extract_blob (src/runtime/api/bun/spawn/stdio.rs:626). The blob there is a blob::Any. BlobExt is implemented for Blob only, so that line does not compile without the method.

@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.

I re-reviewed the latest push and found no bugs; the points from my earlier passes (the empty-view shortcut at stdio[3], the shell refusal's error class/code, and the shell message naming the write direction) are addressed in the code now. Because this intentionally starts refusing inputs that were previously accepted (file-backed Blobs as redis arguments, an S3 Blob in any shell position), a human maintainer should still sign off on that behavior change.

What was reviewed:

  • Blob::in_memory_view rewrite against needs_to_read_file/is_s3 in src/jsc/webcore_types.rs — same store kinds, so no consumer (Blob__sharedView, ServerWebSocket) changes behavior.
  • extract_blob ordering: the Some(0) && fast_size()==0 shortcut, the i != 0 refusal, then the S3 throw — stdout/stderr and stdio[N>2] keep their existing messages, and a bytes-moved-out Blob at stdio[3] still throws.
  • Any::in_memory_view is live (called from extract_blob on an Any), so dead_code = "deny" is not tripped.
  • The redis recorder and S3 stand-in tests run on loopback with port: 0 and release resources in finally/using.
Extended reasoning...

The diff touches six Rust runtime files (Blob store-kind predicate, spawn stdin extraction, shell template handling, node types parser, redis argument parser) plus docs, types and four test files, +485/-50. It touches no auth, crypto or injection surface; the shell path keeps the existing null-byte check. The decisive facts for defer rather than approve: the change deliberately turns previously silent-but-accepted inputs into TypeErrors at four user-facing sites (including redis file-backed Blob args that used to send an empty string), which is a product decision a maintainer should own, and the author is a bot account. All three of my prior inline findings are addressed in commit c200a79 as verified from the code, and the bug hunt ran dry with no new findings.

@robobun

robobun commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Closing as stale: this PR conflicts with main, and its last commit is from 2026-10-24.

The branch stays, so the work is not lost. To pick it up again, rebase the branch on main and reopen this PR.

@robobun robobun closed this Nov 17, 2026
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.

2 participants