maxParts: N rejects a body with exactly N parts (busboy off-by-one) #118

Closed
opened 2026-10-10 16:55:48 +00:00 by chrnx · 1 comment
Owner

maxParts reaches busboy as limits.parts (src/multipart.ts). While implementing #105 (core #117) we observed that with maxParts: N a multipart body with exactly N parts is rejected with 400 Invalid multipart body, so only N−1 parts are actually accepted. The #105 tests only assert that N+1 parts are rejected, so they don't depend on this boundary.

Expected: N parts accepted and N+1 rejected, matching the option's name and docs.

To do:

  • Add a boundary test with exactly N parts (route-level and server-level).
  • Fix the mapping. Either pass maxParts + 1 to busboy, or count the parts ourselves. Check busboy's partsLimit semantics first.
  • Note the change in the CHANGELOG if the accepted count changes.
`maxParts` reaches busboy as `limits.parts` (`src/multipart.ts`). While implementing #105 (core #117) we observed that with `maxParts: N` a multipart body with **exactly N** parts is rejected with `400 Invalid multipart body`, so only N−1 parts are actually accepted. The #105 tests only assert that N+1 parts are rejected, so they don't depend on this boundary. Expected: N parts accepted and N+1 rejected, matching the option's name and docs. To do: - Add a boundary test with exactly N parts (route-level and server-level). - Fix the mapping. Either pass `maxParts + 1` to busboy, or count the parts ourselves. Check busboy's `partsLimit` semantics first. - Note the change in the CHANGELOG if the accepted count changes.
Author
Owner

Fixed in 26.11.0-rc.1 (5536093). From the changelog:

  • maxParts: N accepts exactly N parts (#118). busboy signals its parts limit once the count reaches it, so a body of exactly maxParts parts was rejected with 400 Invalid multipart body and only N−1 got through. busboy now gets one part of headroom, the same way fieldSize does: N parts are accepted and N+1 are rejected, as the option's name says. Both the route-level and the server-level maxParts were affected, on the Node server and app.fetch alike.
Fixed in **26.11.0-rc.1** (`5536093`). From the changelog: - **`maxParts: N` accepts exactly N parts** (#118). busboy signals its parts limit once the count reaches it, so a body of exactly `maxParts` parts was rejected with `400 Invalid multipart body` and only N−1 got through. busboy now gets one part of headroom, the same way `fieldSize` does: N parts are accepted and N+1 are rejected, as the option's name says. Both the route-level and the server-level `maxParts` were affected, on the Node server and `app.fetch` alike.
chrnx closed this issue 2026-11-18 01:04:09 +00:00
Sign in to join this conversation.