Skip to content

fix: handle zero-length slice/subarray at end of multi-buffer#7

Merged
mcollina merged 1 commit into
mainfrom
fix/slice-subarray-end-boundary
Feb 28, 2026
Merged

fix: handle zero-length slice/subarray at end of multi-buffer#7
mcollina merged 1 commit into
mainfrom
fix/slice-subarray-end-boundary

Conversation

@mcollina
Copy link
Copy Markdown
Member

@mcollina mcollina commented Feb 27, 2026

Summary

  • this is the dynamic-buffer side fix for the bug reported in platformatic/kafka#227 (deserialization failure under load)
  • add regression tests for slice() and subarray() when called at the exact end of a multi-buffer DynamicBuffer
  • fix both methods by returning early for zero-length ranges (start === end) before indexing into this.buffers[current]

Reproduction

This issue can be reproduced with:

const b = new DynamicBuffer([Buffer.from([1]), Buffer.from([2])])
b.slice(2) // throws TypeError before this fix

Same for b.subarray(2).

Verification

  • npm test
  • npm run lint

@mcollina mcollina requested a review from ShogunPanda February 27, 2026 17:01
@mcollina mcollina merged commit ba4557d into main Feb 28, 2026
1 check passed
@mcollina mcollina deleted the fix/slice-subarray-end-boundary branch February 28, 2026 09:21
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