Fix multipart limit violations being silently swallowed#6395
Open
Chaoran-Huang wants to merge 1 commit into
Open
Fix multipart limit violations being silently swallowed#6395Chaoran-Huang wants to merge 1 commit into
Chaoran-Huang wants to merge 1 commit into
Conversation
`Multipart.makeChannel` stored the parser's failure and its end-of-parse signal in the same slot, and the terminal `onDone` callback unconditionally overwrote a captured failure with the completion sentinel (`Cause.Done`). The parser keeps running after signalling a limit/parse error and always calls `onDone` at the end, so any violation reached in the same pump as end-of-input was lost — which is always the case when the body arrives in a single chunk. `maxParts` / `maxFileSize` / `maxFieldSize` limits were therefore not enforced and the stream completed normally instead of failing. `onDone` now records completion only when no failure was already captured. Adds a regression test that feeds a 3-part body as a single chunk under `maxParts: 2` and asserts the stream fails with `TooManyParts`. Fixes Effect-TS#6392 Co-Authored-By: Claude Fable 5 <[email protected]>
🦋 Changeset detectedLatest commit: 1e09df5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 27 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of change
Description
Fixes #6392.
Multipart.makeChannel(packages/effect/src/unstable/http/Multipart.ts) stores the parser's failure and its end-of-parse signal in the sameexitslot. multipasta keeps running after it signals a limit/parse error and always callsonDoneat the end, and the terminalonDonehandler unconditionally overwrote a previously captured failure with the completion sentinel:The consuming
looponly inspectsexitoncepartsBufferis drained — which happens after the pump pull that callsparser.end()(→onDone). Whenever the violation and end-of-input are reached in the same delivery — always the case when the body arrives in a single chunk, i.e. essentially every small upload — the capturedMultipartErroris overwritten byCause.Done()and the stream completes normally. In practice this meansmaxParts,maxFileSize, andmaxFieldSizeare silently not enforced (maxTotalSizestill trips because the body stream'sMaxBodySizeaborts it independently, beforeonDone).Fix
onDonenow records normal completion only when no failure was already captured:onDoneis multipasta's terminal callback (fires once, after anyonError), so first-signal-wins is the correct precedence.Test
Adds a regression test that feeds a 3-part body as a single chunk under
maxParts: 2and asserts the stream fails withTooManyParts. Verified it fails before the fix (the stream wrongly completes) and passes after — the two pre-existing Multipart tests remain green (vitest run test/unstable/http/Multipart.test.ts: 3 passed).Note on affected versions
Reported against the published
@effect/platform(0.94.5 and 0.97.0), where the same clobber usesExit.void; onmainthe module has moved toeffect/unstable/httpand the sentinel isCause.Done(), but the bug and fix are identical. Maintainers may want to backport to the@effect/platformline.🤖 Generated with Claude Code