Skip to content

fix: preserve bitlist inputs when reusing byte buffers - #563

Open
yinbowen-dc wants to merge 1 commit into
ChainSafe:masterfrom
yinbowen-dc:codex/fix-559-preserve-bitlist-input
Open

yinbowen-dc wants to merge 1 commit into
ChainSafe:masterfrom
yinbowen-dc:codex/fix-559-preserve-bitlist-input

Conversation

@yinbowen-dc

@yinbowen-dc yinbowen-dc commented Nov 19, 2026 •

Copy link
Copy Markdown

Motivation

Closes #559. deserialize(bytes, {reuseBytes: true}) clears the non-byte-aligned bitlist delimiter in the caller's buffer. Decoding it again can change the bit length or fail, including inside containers.

Description

  • Copy non-byte-aligned bitlists before masking their last byte. Byte-aligned bitlists and other reusable container fields continue sharing their backing buffers.
  • Pass each BitList / ProgressiveBitList limit into the shared decoder and validate it before allocating a copy. This also covers tree decoding and avoids an input-sized allocation for already-invalid data.
  • Document the exception to byte reuse.
  • Add 52 regression cases covering repeated decoding, serialization round trips, Buffer / Uint8Array subarrays, empty and byte-aligned lists, bounded and unbounded progressive lists, mixed containers, and limit rejection before copying.

An earlier contribution (#560) was closed when its author deleted the head repository. This is an independent implementation for the still-open issue; no existing active fix was found. Constructor size bounds discussed in #562 are outside this change.

Steps to test or reproduce

Node 22.23.4, pnpm 10.23.0:

  • New regression file: 52 passed; 34 failed / 18 passed on the unmodified decoder.
  • pnpm -r test:unit --coverage.enabled=false --reporter=dot: 3,155 passed, 3 existing skipped (all four workspace packages).
  • pnpm build and pnpm check-types: passed for all workspace packages.
  • pnpm lint, pnpm lint:no-push-spread, and git diff --check: passed.

Downloaded consensus-spec suites and browser suites were not run.

AI assistance: Codex implemented and tested this patch. Maintainer review is still needed; no human review is claimed.

@yinbowen-dc
yinbowen-dc requested a review from a team as a code owner November 19, 2026 07:03
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T07:05:07.609309Z d16f42d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

This branch has not been deployed

No deployments
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.

BitList deserialization with reuseBytes: true mutates the input buffer

1 participant