Skip to content

Conversation

@paolobarbolini
Copy link
Contributor

@paolobarbolini paolobarbolini commented Nov 23, 2025

This documents that BytesMut may not preserve the memory outside of 0..len after calling BytesMut::reserve. It may for example discard all of it, and replace it with uninit memory in the fallback case, or even shift it causing a different region of the BytesMut to appear when going through the reclaim optimization.

This was encountered in snapview/tungstenite-rs#524 (comment) after #805 was closed, which could have lead to unsound code being merged into tungstenite.

@paolobarbolini paolobarbolini force-pushed the bytesmut-reserve-footgun branch from 1151d5f to dec048b Compare November 27, 2025 14:18
@paolobarbolini paolobarbolini force-pushed the bytesmut-reserve-footgun branch from dec048b to 70efacc Compare November 27, 2025 14:19
@paolobarbolini paolobarbolini changed the title Document that BytesMut::reserve may not preserve memory outside 0..len Document that BytesMut::{reserve,try_reserve} doesn't preserve unused capacity Nov 27, 2025
@paolobarbolini paolobarbolini marked this pull request as ready for review November 27, 2025 14:19
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 94e4291 into tokio-rs:master Nov 28, 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.

2 participants