fix(multipart): accept exactly maxParts parts (#118)
CI / dco (pull_request) Successful in 5s
CI / runtimes (bun) (pull_request) Successful in 20s
CI / build (pull_request) Successful in 30s
CI / runtimes (edge) (pull_request) Successful in 19s
CI / runtimes (deno) (pull_request) Successful in 34s

busboy emits `partsLimit` once its part count reaches `limits.parts`,
not when it passes it, and parseMultipart treats that event as a
malformed body. With `maxParts: N` a body of exactly N parts was
therefore rejected with 400 and only N-1 were accepted.

parseMultipart now passes `maxParts + 1` to busboy, the same one-unit
headroom it already gives `fieldSize`. N parts are accepted, N+1 are
rejected. Route-level and server-level maxParts share this path, as do
the Node server and app.fetch.

test/multipart.test.ts adds the exact-N case on parseMultipart;
test/multipart-http.test.ts sends exactly N parts at route and server
level. All three new assertions fail without the fix.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-10-24 22:21:10 -05:00
1 parent 87b6e7a4b0
commit 5536093894
4 files changed
+18 -1

No files matched your search

+4 -1
View File
@@ -99,11 +99,14 @@ export function parseMultipart(raw: Buffer, boundary: string, opts: MultipartOpt
// busboy flags a field as truncated once it *reaches* `fieldSize`, so a field of exactly
// `maxFieldBytes` needs one byte of headroom to count as whole.
const fieldSize = opts.maxFieldBytes === undefined ? undefined : opts.maxFieldBytes + 1;
// Same for parts: busboy emits `partsLimit` once the count *reaches* `parts`, so a body of
// exactly `maxParts` parts needs one of headroom to be accepted (Gitea #118).
const parts = opts.maxParts + 1;
try {
bb = busboy({
headers: { 'content-type': `multipart/form-data; boundary=${boundary}` },
limits: { parts: opts.maxParts, fieldSize },
limits: { parts, fieldSize },
});
} catch {
return fail();