GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(dicer): finish a part whose header block ends at the delimiter by yxshee · Pull Request #239 · fastify/busboy

Conversation

@yxshee

@yxshee yxshee commented Nov 9, 2026

Copy link
Copy Markdown

Problem

A part that consists of headers only, with the delimiter following the last header line directly, makes Busboy hang: neither finish nor error is ever emitted.

const Busboy = require('@fastify/busboy')
const bb = new Busboy({ headers: { 'content-type': 'multipart/form-data; boundary=b' } })
bb.on('field', (name, value) => console.log('field', name, JSON.stringify(value)))
bb.on('finish', () => console.log('finish'))
bb.on('error', err => console.log('error', err.message))
bb.end(Buffer.from(
  '--b\r\n' +
  'Content-Disposition: form-data; name="x"\r\n' +   // no empty line, no body
  '--b--\r\n'))
// (nothing, ever)

RFC 2046 §5.1.1 defines body-part := MIME-part-headers [CRLF *OCTET], so the empty line and the body are optional together; the message above is well-formed. Go's mime/multipart returns a part named x with an empty body; busboy 1.x reports Malformed part header. @fastify/busboy does neither, and in a server the request never completes.

What happens inside Dicer: 'header' is only emitted when HeaderParser sees CRLF CRLF. Here the boundary search matches \r\n--b first, _oninfo resets the header parser and ends the part with push(null). The part never got a 'header' event, so Multipart never attaches data/end listeners or resumes it, the part's 'end' never fires, _parts never returns to 0, and the deferred 'finish' never goes out. The same path is taken whenever a delimiter arrives while a header block is open, for example after a body line that merely starts with the boundary (--b-), which is why those inputs also hang instead of erroring.

Fix

At the match, if the header block of a (non-preamble) part is still open, finish the header parser before ending the part. The needle starts with CRLF, so the parser always holds complete header lines at that point; the part is then delivered like any other, with an empty body. Parts with no usable headers are skipped by Multipart as before.

With this change finish is emitted for the input above (field x ""), and --b--style inputs terminate instead of hanging. Treating --b- as body text, as Go does, would need the delimiter check to be deferred until the bytes after the boundary are known; that is a larger change and out of scope here.

Found by comparing busboy, @fastify/busboy and Go's mime/multipart over generated multipart bodies (the other divergence, transport padding after a boundary line dropping the next part, is fixed in a separate PR).

Checklist

  • run npm run test and npm run benchmark
  • tests and/or benchmarks are included — test/dicer-header-only-part.test.js (two header-only parts: headers emitted, both parts end, Dicer finishes) and two cases in test/types-multipart.test.js (header-only fields around a normal field, and a header-only file part)
  • documentation is changed or added — n/a
  • commit message follows commit guidelines

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@yxshee
fix(dicer): finish a part whose header block ends at the delimiter
f241ca5
RFC 2046 section 5.1.1 makes the body of a part optional: a part may be
nothing but headers, so the delimiter can follow the last header line
directly instead of an empty line:

  --b\r\n
  Content-Disposition: form-data; name="x"\r\n
  --b--

Dicer only emitted 'header' when the header parser saw CRLF CRLF. When
the boundary search matched first, the header parser was reset, the part
never got a 'header' event, nobody read it, its 'end' never fired and
Dicer never finished: Busboy emitted neither 'finish' nor 'error' and
the request hung. Go's mime/multipart and busboy 1.x handle this input
(the latter as an error).

The needle starts with CRLF, so at the match the header parser always
holds complete lines. Finish it there and emit the header, so the part
is delivered with an empty body like any other.
@yxshee yxshee closed this Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@yxshee
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.