Repository navigation
Conversation
…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.
|
Updated 6:56 AM PT - Oct 24th, 2026
✅ @robobun, your commit c200a79c58a9f7e0e7cb9fef6484d2418cf23411 passed in 🧪 To try this PR locally: bunx bun-pr 46673That installs a local version of the PR into your bun-46673 --bun |
|
Status Reproduced on main 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 []
The new tests fail with the released 1.4.3 ( CI on PR: #46673 |
|
Warning Review limit reachedYou'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. View limit details
No actionable comments were generated in the recent review.
|
| 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:
Merge Risk: 
Minimal · up to 1b269
-
No concrete issue currently prevents merging; complete the normal build and test checks.
Pre-merge checks: 
4
-
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.
Comment @coderabbitai help to get the list of available commands.
There was a problem hiding this comment.
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.
…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.
`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.
…lob-sync-consumers
There was a problem hiding this comment.
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.
… 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)`.
|
On the note that |
There was a problem hiding this comment.
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_viewrewrite againstneeds_to_read_file/is_s3insrc/jsc/webcore_types.rs— same store kinds, so no consumer (Blob__sharedView,ServerWebSocket) changes behavior.extract_blobordering: theSome(0) && fast_size()==0shortcut, thei != 0refusal, then the S3 throw — stdout/stderr andstdio[N>2]keep their existing messages, and a bytes-moved-out Blob atstdio[3]still throws.Any::in_memory_viewis live (called fromextract_blobon anAny), sodead_code = "deny"is not tripped.- The redis recorder and S3 stand-in tests run on loopback with
port: 0and release resources infinally/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.
|
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. |
Related to #43931
Problem
Blobis read as empty at four sites: spawnstdin, a$redirect,Bun.buildfilesand redis arguments. There is no request and no error.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 andBlobOrStringOrBuffer::from_jsthrow for an S3-backed Blob.extract_blobgoes by the bytes, not the size field. A Blob emptied bynew Response([blob])no longer leaves stdin open.WebSocket.send(WebSocket: real closing handshake, one failure path,wsrewritten on native transports (consolidates the open WebSocket PRs) #45223) throws for the same input.spawn-empty-arrayBufferOrBlob.test.ts,bunshell-file.test.ts,bundler_files.test.tsandbuffer-operations.test.tsfail on 1.4.3. Also ranspawn.test.ts,bunshell.test.tsand bindgen. Self-reviewed: 9 concerns raised, 9 addressed.Background
Blobviews a store: memory, a file, or an S3 key. Only memory has bytes at once.Stdio::extract_blobmakes a Blob a child's stdin.BlobOrStringOrBuffer::from_jsparsesBun.buildfilesand redis arguments. Its opt-outFileBlobs::Allowhad one user, redis, and is deleted.|| is_s3()at each guard: a fourth store kind passes them. Considered streaming into stdin: a failed GET exits 0.Downsides
echo hi < ${s3file}(printedhi),s3file.slice(0, 0)as stdin (was empty),redis.set(key, Bun.file(p))(stored"").extract_blob..text: +256 bytes. No new allocation or syscall.socket.write(s3file),import()of an S3Fileblob: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.servestands in for S3 and counts requests. Linux x64.Bun.spawn/Bun.spawnSyncstdinorstdio[0]: anS3File,Bun.file("s3://..."), a slice,new Blob([s3file]), aRequestbody,new Response([s3file])"", exit 0, 0 requests. WithBUN_FEATURE_FLAG_DISABLE_MEMFD=1(the path of macOS and Windows) the call never endsTypeError(ERR_INVALID_ARG_TYPE), 0 requests$`cat < ${s3file}`,$`wc -c < ${s3file}`$`echo hi < ${s3file}`hi$`echo hi > ${s3file}`Cannot redirect stdout/stderr to an immutable blob)Bun.writefor this direction$`cat < ${new Response([s3file])}`catas an external command:TypeErrorfrom spawn when the command starts. A builtin that reads stdin still gets""(see below)Bun.build({ files: { "/entry.js": s3file } })TypeError: File blob cannot be used hereredis.set(key, s3file),redis.set(key, Bun.file(path))SET key ""TypeError: File blob cannot be used here, no command sent<: a Blob emptied bynew Response([blob])stdin: await s3file.bytes(),< ${await s3file.bytes()}stdout: s3file,stdio[3]: s3fileTypeErrortextsstdio[3]: a Blob emptied bynew Response([blob])TypeError: Blob cannot be used for stdio[3] yet< ${Bun.file(fd)},< ${Bun.file(path)}Error texts.
An S3-backed Blob cannot be used as stdin. Pass await blob.bytes() instead(TypeError,ERR_INVALID_ARG_TYPE, like the other stdio refusals inextract_blob).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.buildfilesand redis:File blob cannot be used here(TypeError,ERR_INVALID_ARG_TYPE): the text thatBun.filealready got infiles, and that bindgen uses for both kinds.await blob.bytes()and notblob.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
spawnSynccannot wait for a GET. Node also refuses when the call is made: a Blob instdiothrowsERR_INVALID_ARG_VALUEfromspawn(v26.3.0).Measurements. Release builds (
--profile=release, ThinLTO) of main6292c6539dand of that commit plus the commits of this PR, Linux x64. Instruction counts aregdbstepifrom 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.extract_blobinclude its callees)write_or_endand its node:http twin, shell builtin stdin for a Response body, theblob:module source and its bundler twin, theBun.serveBlob body). Conflicted files vs net, tls: consolidate the open node:net, node:tls, Bun.connect, Bun.listen and usockets pull requests #46522/http, net, tls: consolidate the open fetch, Bun.serve, node:http, node:http2, HTTP/3, node:net and node:tls pull requests #46528/spawn: close the parent's stdin memfd when spawn_process returns, not at GC #46491/Bun.Archive: read Bun.file() input from disk instead of writing empty bytes #41193: 0/0/0/0 new (http, net, tls: consolidate the open fetch, Bun.serve, node:http, node:http2, HTTP/3, node:net and node:tls pull requests #46528 conflicts with main already in 29 files, Bun.Archive: read Bun.file() input from disk instead of writing empty bytes #41193 in 3)BlobOrStringOrBufferparse (Bun.buildfiles): a 17-byte string 388 -> 387, an in-memory Blob 199 -> 195 instructionsWhere 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.handle_template_valuespillsdepth(two stack moves) and runs one alignmentnopless. No branch is added on that path..text(+256):extract_blob+94 bytes,handle_template_value+47, the parser -27 (from_js_maybe_file849, nowfrom_js822), and section alignment.git merge-treeagainst 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 indocs/runtime/shell.mdx: both add a paragraph after the same list.How the syscall and allocator numbers were taken:
straceis not installed here, sogdbcountedcatch syscallstops (memfd_create, ftruncate, pwrite64, pipe2, close, socketpair) and breakpoint hits onmi_malloc,mi_zalloc,mi_reallocin the parent, for loops of 100 and 200Bun.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 checkstops inbun_jsc(5 errors) and, with those patched, inbun_runtime(15 errors). Two of the 15 are new with this PR:in_memory_view(Blob.rs) andhandle_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.
socket.write(s3file)andsocket.end(s3file)send 0 bytes.write()andend()are typedstring | BufferSource, and net, tls: consolidate the open node:net, node:tls, Bun.connect, Bun.listen and usockets pull requests #46522 rewrites that function. Handed off, with measurements: a guard that only tests costs 15 instructions on eachsocket.write(string), a guard that returns the bytes saves 16.< ${response}when the body is an S3 Blob and the command is a shell builtin that reads stdin (caton Windows):"". Handed off to shell: reject a stream, used, failed or S3-backed Response body as stdin #42786, which owns the check of a Response body.import()of ablob:URL (src/runtime/jsc_hooks.rs) and its bundler twin (src/bundler/options.rs): an empty module. Handed off.new Blob(["x", s3file])drops the S3 part when it is made, so every consumer sees"x"(Blob: read file-backed parts in multi-part new Blob([...]) #33600, reported for files as Blob constructor ignores File parts if more than one part is given #25851).Bun.serveresponse whose body is an S3 Blob made bynew Response([s3file]): empty. Tests from Hardening: fix crashes across the runtime, bundler, dev server, shell and CLI #46021 pin it.Bun.Archiveentries (Bun.Archive: read Bun.file() input from disk instead of writing empty bytes #41193), FormData parts (FormData: throw when serializing an S3-backed entry instead of sending an empty part #38364),structuredClone(Throw DataCloneError when structured-cloning an S3File #37905),formData()(formData(): read a file- or S3-backed Blob body before parsing it #45161),FormData.from(blob), a macro that returns the Blob.src/runtime/socket/uws_jsc.rs): node:http refuses a Blob chunk in JS before it, and http, net, tls: consolidate the open fetch, Bun.serve, node:http, node:http2, HTTP/3, node:net and node:tls pull requests #46528 deletes the function.Bun.file(path).slice(a, b)as stdin gives the child the whole file (spawn: send a sliced Bun.file() at stdin in chunks of its window #44301, Honor Bun.file().slice() bounds in Bun.write #41209).Adjacent, not changed.
stdin: s3file.stream()works, but a failed GET is lost: the child reads""and exits 0. It is the same for everyReadableStreamstdin 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.
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) andtest/js/valkey/unit/buffer-operations.test.ts(2).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. TheBun.file(fd)redirect test, the three spawn controls and the in-memory redis test pass on both: they pin what must not change.extract_blob(the zero-size cases and both moved-out cases), and two that belonged to hunks that left this PR.spawn-empty-arrayBufferOrBlob.test.ts23 pass,bunshell-file.test.ts4 pass,bundler_files.test.ts29 pass,buffer-operations.test.ts2 pass (9 need Docker).bunshell.test.tsandspawn.test.tsran 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 > sharpinstalls from the npm registry, andstdout can be readtook 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 usesstdin: "ignore"andstdout: "pipe", no Blob, and CI ranspawn.test.tsgreen on every lane for the first push.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, shellyield,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 aTypeErrorwithERR_INVALID_ARG_TYPE. Its text names the write remedy. The emptiness tests inextract_blobare two plain conditions. One thing did not change: spawn takes the body of aRequestorResponsebeforeextract_blobrefuses it, sobodyUsedis 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
Responsecase 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, thes3://spelling, aBun.file(fd)control and a check that can see a stray request. Not done: the review also offered to write the twoshared_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)
passes on PR (with fix)
diff hotspot
gate history · 1 passed · 0 rejected · iteration 0
evidence per changed file