Skip to content

fix: decode array stream headers across chunk boundaries - #298

Draft
liuyinchu wants to merge 2 commits into
msgpack:mainfrom
liuyinchu:fix-fragmented-array-header-20261030
Draft

liuyinchu wants to merge 2 commits into
msgpack:mainfrom
liuyinchu:fix-fragmented-array-header-20261030

Conversation

@liuyinchu

Copy link
Copy Markdown

Problem

decodeArrayStream() reads the outer array header outside its incomplete-data handling block. An array16 or array32 length field split across stream chunks therefore raises a RangeError before the remaining bytes can arrive.

This also affects canonical encoder output: encode an array of 16 objects, yield its first byte in one chunk, and yield the rest in the next chunk. Decoding the same bytes in one chunk succeeds.

Change

  • Read the outer array header inside the existing resumable decoding block.
  • Keep the header pending until its length field has been read completely.
  • Reject streams that end before the array header is complete.

Tests cover every split inside array16/array32 headers, byte-at-a-time input with empty chunks and non-zero view offsets, nested values, and truncated headers. No other stream validation behavior is changed intentionally.

Validation

  • Regression tests on the base revision: 4 failed, 2 passed.
  • Patched full Node suite: 333 passed.
  • ESLint and TypeScript checks passed.
  • A separate AI reviewer reran the array-stream tests: 15 passed.
  • Browser execution could not start in the test environment because Chromium socket creation was denied; Deno/Bun/Firefox were not run.

AI assistance

This patch, tests, and draft were prepared with OpenAI Codex assistance and independently reviewed by another AI agent. The test results above are from executed checks; this does not claim a human code review.

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.

1 participant