Skip to content

fix(modem): validate stream type in demuxStream and flush on end#195

Merged
apocas merged 1 commit into
apocas:masterfrom
joshtrichards:patch-1
Mar 20, 2026
Merged

fix(modem): validate stream type in demuxStream and flush on end#195
apocas merged 1 commit into
apocas:masterfrom
joshtrichards:patch-1

Conversation

@joshtrichards

Copy link
Copy Markdown
Contributor

Problem

demuxStream blindly trusts the first byte of each 8-byte header as a valid Docker multiplex stream type. When the stream is not actually multiplexed (e.g. TTY mode) or framing becomes misaligned, a garbage type byte causes a garbage frame length, which misaligns every subsequent frame. The result is corrupted leading bytes in the demuxed output.

This forces downstream consumers to add workarounds like:

// fix dockerode bug returning invalid leading characters
JSON.parse(json.substring(json.indexOf('{')))

See for example:

Related (may fix) issues:

Changes:

  • Validate the stream type byte (must be 0, 1, or 2) after reading each header. On an invalid value, flush all buffered data to stdout and switch to raw passthrough for the rest of the stream.
  • Listen for the source stream's end event and flush any remaining buffered bytes to stdout instead of silently dropping them.

@apocas apocas merged commit 55c10b9 into apocas:master Mar 20, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants