Title: fleet(dispatch): dechunked_len does unchecked arithmetic on the peer-declared chunk size — overflow panics in debug, wraps in release · Issue #6512 · developing-today/code · GitHub
Open Graph Title: fleet(dispatch): dechunked_len does unchecked arithmetic on the peer-declared chunk size — overflow panics in debug, wraps in release · Issue #6512 · developing-today/code
X Title: fleet(dispatch): dechunked_len does unchecked arithmetic on the peer-declared chunk size — overflow panics in debug, wraps in release · Issue #6512 · developing-today/code
Description: Summary fleet-dispatch's hand-rolled HTTP response reader does unchecked arithmetic on the peer-declared chunk size in dechunked_len — the function read_response uses to decide whether a chunked body is complete. A chunk-size line naming...
Open Graph Description: Summary fleet-dispatch's hand-rolled HTTP response reader does unchecked arithmetic on the peer-declared chunk size in dechunked_len — the function read_response uses to decide whether a chunked bo...
X Description: Summary fleet-dispatch's hand-rolled HTTP response reader does unchecked arithmetic on the peer-declared chunk size in dechunked_len — the function read_response uses to decide whether a chunke...
Opengraph URL: https://github.com/developing-today/code/issues/6512
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"fleet(dispatch): dechunked_len does unchecked arithmetic on the peer-declared chunk size — overflow panics in debug, wraps in release","articleBody":"## Summary\n\n`fleet-dispatch`'s hand-rolled HTTP response reader does unchecked arithmetic on the peer-declared chunk size in `dechunked_len` — the function `read_response` uses to decide whether a chunked body is complete. A chunk-size line naming one of the two largest `usize` values panics in debug/test builds (`attempt to add with overflow`) and, in release builds where overflow checks are off, wraps so the completeness guard and the slice index are computed from wrapped values. The sibling decoder `dechunk` in the same file guards the same declared size before slicing and handles the identical input safely — the two halves of the chunked reader disagree about whether peer-declared sizes can be trusted.\n\nThis is the #5579 rule (\"peer-declared sizes are never trusted\") applied everywhere else in the fleet HTTP readers — fleet-proxy's `http.rs` caps chunk sizes against `MAX_RESPONSE_BODY_BYTES` with `checked_add` before allocating — but missed in the dispatch client.\n\n## Evidence (verified this run, laptop, origin/main `540d3bea3f`)\n\n`pkgs/fleet/crates/fleet-dispatch/src/lib.rs`:\n\n- `:303` — `let size = usize::from_str_radix(size_str.trim().split(';').next()?.trim(), 16).ok()?;` — the chunk size is parsed straight from the response bytes, unbounded.\n- `:308` — `if rest.len() \u003c size + 2 { return None; }` — `size + 2` is unchecked: for `size = usize::MAX` or `usize::MAX - 1` this overflows.\n- `:311` — `total += size;` — also unchecked.\n- `:312` — `rest = &rest[size + 2..];` — slices at the same unchecked expression.\n- `read_response` (`:273`, the `complete` closure at `:265-272`) calls `dechunked_len(body)` after every read while filling a chunked body, so the panic/wrap triggers mid-exchange on response bytes alone — no local input needed beyond running `fleet dispatch status|launch|enqueue` against an endpoint that returns such a chunk-size line.\n- Contrast `:326` — `dechunk` checks `size == 0 || rest.len() \u003c size` before slicing and never adds to the declared size; and `pkgs/fleet/crates/fleet-proxy/src/http.rs` `read_chunked`, which does `out.len().checked_add(size)` and refuses anything past `MAX_RESPONSE_BODY_BYTES` before allocating.\n\n### Probe (real crate, laptop worktree `~/git/fleet/probe-dispatch-dechunk-wt` at `540d3bea3f`)\n\nA temporary `#[test]` appended to the crate's own test module, run with `cargo test -p fleet-dispatch probe_dechunked_len_huge_chunk_size -- --nocapture`:\n\n- Control: `dechunked_len(b\"4\\r\\nWiki\\r\\n5\\r\\npedia\\r\\n0\\r\\n\\r\\n\") == Some(9)` ✔\n- Control: `dechunked_len(b\"4\\r\\nWi\") == None` ✔\n- Control: `dechunk(b\"ffffffffffffffff\\r\\nXX\") == []` — the decoder is safe on the same bytes ✔\n- `dechunked_len(b\"ffffffffffffffff\\r\\nXX\")` → **PANIC** at `crates/fleet-dispatch/src/lib.rs:308:25: attempt to add with overflow`\n- `dechunked_len(b\"fffffffffffffffe\\r\\nXX\")` → **PANIC** at the same line\n- Probe result: `PROBE DONE panics=true true`, test passed (panics caught via `catch_unwind`).\n\nIn a release build the same expressions wrap instead of panicking: `size + 2` becomes `1` (for `MAX`) or `0` (for `MAX - 1`), the `:308` guard passes against a 2-byte remainder, `total` wraps, and `rest[size + 2..]` advances by the wrapped index — the completeness verdict for the exchange is then computed from wrapped arithmetic while `dechunk` decodes something else, so the client can finish an exchange early on a body the decoder reads differently.\n\n## Why it matters\n\n`fleet dispatch` is the thin client every seat uses to launch and enqueue sessions through pm-dispatch, over both the direct and the CONNECT-tunnel transports. Its response reader is the one hand-rolled HTTP reader in the fleet workspace that still does raw arithmetic on a peer-declared length. pm-dispatch (Bun.serve) will not emit such a chunk size itself, but the reader's contract — per #5579 and the module's own framing — is that response framing is validated before it is trusted: a buggy, compromised, or mis-proxied endpoint (the tunnel path traverses the egress proxy) turns a status/launch/enqueue call into a client panic in debug builds and a silently wrong completeness verdict in release builds, instead of the crate's normal `DispatchError::Transport` exit-3 path. Panics also bypass the crate's exit-code contract (0/2/3/4) entirely.\n\n## Acceptance criteria\n\n- [ ] `dechunked_len` uses checked arithmetic (e.g. `size.checked_add(2)`, a checked running total, and/or a bound of the declared size against the remaining bytes / the existing 64 MiB body cap) so no peer-declared chunk size can overflow, wrap, or panic in any build profile.\n- [ ] A chunk-size line that cannot describe a body within the buffered remainder (including the `usize::MAX` / `usize::MAX - 1` cases) is treated as \"not complete\" or as a transport error — never as a completed body computed from wrapped values.\n- [ ] Unit tests in `fleet-dispatch` pin: the two overflow sizes above, a large-but-plausible size with insufficient bytes (`None`/error, no panic), and the existing happy-path pins (`chunked_bodies_dechunk`) keep passing.\n- [ ] `cargo test -p fleet-dispatch` passes on the laptop or in CI.\n\nScope note: `read_response`'s Content-Length handling and `dechunk` itself are out of scope except where the fix naturally shares a guard; the pooled-connection desync concerns of #5579 do not apply here (one exchange per connection, `Connection: close`).\n","author":{"url":"https://github.com/dezren39","@type":"Person","name":"dezren39"},"datePublished":"2026-11-06T12:40:36Z","url":"https://github.com/developing-today/code/issues/6512"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:2016087d-f782-4174-e374-f35b758a8ee5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E14C:2622A:8254FE:A8C37E:6B062CD9 |
| html-safe-nonce | 7887f3ebcd26e39f6dcc315c69bd360859d4a41b3ca19f84432bf6d244f24280 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMTRDOjI2MjJBOjgyNTRGRTpBOEMzN0U6NkIwNjJDRDkiLCJ2aXNpdG9yX2lkIjoiODY2OTk4MjA3NjgzOTUzNzg4MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 276d1badc2a083af761f9d07af5ab6a8f38c8efb2fe6c45a9badeb665b991567 |
| hovercard-subject-tag | issue:6242820532 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/developing-today/code/6512/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1d22f2c4670649a816ba7306ab84002a302337d10f61e6a7ecabfc61023c1aa5/developing-today/code/issues/6512 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1d22f2c4670649a816ba7306ab84002a302337d10f61e6a7ecabfc61023c1aa5/developing-today/code/issues/6512 |
| og:image:alt | Summary fleet-dispatch's hand-rolled HTTP response reader does unchecked arithmetic on the peer-declared chunk size in dechunked_len — the function read_response uses to decide whether a chunked bo... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dezren39 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7f961de5dd5c5d4aca24d33f8b3ffb3fb8b2ef53d0a4f32f01f0a790e512f6d3 |
| turbo-cache-control | no-preview |
| go-import | github.com/developing-today/code git https://github.com/developing-today/code.git |
| octolytics-dimension-user_id | 26439447 |
| octolytics-dimension-user_login | developing-today |
| octolytics-dimension-repository_id | 627308783 |
| octolytics-dimension-repository_nwo | developing-today/code |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 627308783 |
| octolytics-dimension-repository_network_root_nwo | developing-today/code |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 494ea0bb1e0feef734a83e2628697647755e8864 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width