Skip to content

fix(js): prevent double free on Buffer by passing a BufferSlice - #369

Merged
barjin merged 1 commit into
masterfrom
fix/use-buffer-reference
Jan 29, 2026
Merged

barjin merged 1 commit into
masterfrom
fix/use-buffer-reference

Conversation

@barjin

@barjin barjin commented Jan 29, 2026

Copy link
Copy Markdown
Member

As a non-async function, decode_buffer doesn't require owning the Buffer and can do with only a BufferSlice. This takes the cleanup responsibility from napi-rs and should prevent the double free scenarios, as the Buffer is now Node runtime-managed.

Closes #368

@barjin
barjin requested a review from Copilot January 29, 2026 10:49
@barjin barjin self-assigned this Jan 29, 2026
@github-actions github-actions Bot added this to the 133rd sprint - Tooling team milestone Jan 29, 2026
@github-actions github-actions Bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Jan 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical double-free issue in the Node.js bindings under high-concurrency conditions by changing the decode_buffer function to accept a BufferSlice instead of an owned Buffer.

Changes:

  • Changed parameter type from Buffer to BufferSlice in decode_buffer method
  • Updated the import to use BufferSlice instead of Buffer
  • Simplified buffer usage from buffer.to_vec().as_slice() to &buffer (more efficient as it avoids copying)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@barjin
barjin merged commit cd2daf0 into master Jan 29, 2026
34 checks passed
@barjin
barjin deleted the fix/use-buffer-reference branch January 29, 2026 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nodejs: Double free on napi-rs Buffer in decode_buffer

3 participants