Repository navigation
fix: preserve bitlist input when reusing bytes - #560
GiHoon1123 wants to merge 2 commits into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 816e49d132
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // the last byte is > 1, so a padding bit will exist in the last byte and need to be removed | ||
| const uint8Array = slice(data, start, end, reuseBytes); | ||
| // Copy even when reusing bytes so clearing the padding bit leaves the input intact. | ||
| const uint8Array = slice(data, start, end); |
There was a problem hiding this comment.
Validate the bitlist limit before copying
When reuseBytes is enabled and an untrusted non-byte-aligned bitlist exceeds the configured limit, this unconditional copy duplicates the entire field before BitListType or ProgressiveBitListType checks bitLen after the helper returns. A caller using reuse specifically to avoid allocations can therefore be forced into an input-sized allocation (and possible OOM) for data that is immediately rejected; compute and validate the bit length or serialized bound before taking this copy.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 083ea0f. Both bitlist types now pass their limit to the shared decoder, which checks the bit length before slicing. Added tests for value and tree decoding that verify over-limit inputs never reach slice or subarray.
|
Could someone take a look at this PR when they have a chance? Happy to address any feedback. Thanks! |
Motivation
With
reuseBytes: true, decoding a non-byte-aligned bitlist clears its padding bit in the input buffer. Decoding the same bytes again can then return a different length or throw.Description
Check the bit length before copying the bitlist bytes and clearing the padding bit. Byte-aligned bitlists and other fields still reuse their buffers. The shared decoder covers both
BitListTypeandProgressiveBitListType.Add regression tests for input preservation, repeated decoding, subarrays, length limits, and buffer reuse in mixed containers. Over-limit inputs are rejected before slicing in both value and tree decoding. Document the sharing behavior on
deserialize().Closes #559
Steps to test or reproduce
pnpm -r test:unit --coverage.enabled=false --reporter=dotpnpm -r check-typespnpm lintandpnpm lint:no-push-spreadThe 86 regression cases also passed in Chrome and Firefox against the built JS. Direct browser execution of the TS sources hits the existing
ByteViewstype-export error, also reproduced with the existing bitlist tests.