Skip to content

fix: BytesMut only reuse if src has remaining#803

Merged
Darksonn merged 5 commits intotokio-rs:masterfrom
discord9:fix/copy_to_bytes
Nov 14, 2025
Merged

fix: BytesMut only reuse if src has remaining#803
Darksonn merged 5 commits intotokio-rs:masterfrom
discord9:fix/copy_to_bytes

Conversation

@discord9
Copy link
Copy Markdown
Contributor

@discord9 discord9 commented Nov 13, 2025

prevent stack overflow in this case:

let mut buf = BytesMut::new();
buf.put(&[] as &[u8]);

closes #802

Signed-off-by: discord9 <discord9@163.com>
Signed-off-by: discord9 <discord9@163.com>
Signed-off-by: discord9 <discord9@163.com>
@discord9 discord9 changed the title fix: default impl of Buf fix: BytesMut only reuse if src has remaining Nov 14, 2025
@discord9
Copy link
Copy Markdown
Contributor Author

@paolobarbolini is this fix reasonable?

Copy link
Copy Markdown
Member

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

Thanks for finding this!

Overall looks good, but I have a suggested alternative implementation.

Comment thread src/bytes_mut.rs Outdated
Comment thread src/bytes_mut.rs Outdated
Signed-off-by: discord9 <discord9@163.com>
Signed-off-by: discord9 <discord9@163.com>
Copy link
Copy Markdown
Member

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

Thanks.

@Darksonn Darksonn merged commit 60cbb77 into tokio-rs:master Nov 14, 2025
18 checks passed
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.

Impl of Buf with default copy_to_bytes impl could stack overflow

2 participants