Skip to content

Conversation

@discord9
Copy link
Contributor

@discord9 discord9 commented Nov 13, 2025

prevent stack overflow in this case:

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

closes #802

@discord9 discord9 changed the title fix: default impl of Buf fix: BytesMut only reuse if src has remaining Nov 14, 2025
@discord9
Copy link
Contributor Author

@paolobarbolini is this fix reasonable?

Copy link
Contributor

@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.

Signed-off-by: discord9 <[email protected]>
Signed-off-by: discord9 <[email protected]>
Copy link
Contributor

@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