Integer overflow in `BytesMut::reserve`
In the unique reclaim path of `BytesMut::reserve`, the condition ```rs if v_capacity >= new_cap + offset ``` uses an unchecked addition. When `new_cap + offset` overflows `usize` in release builds, this condition may incorrectly pass, causing `self.cap` to be set to a value that exceeds the actual allocated capacity. Subsequent APIs such as `spare_capacity_mut()` then trust this corrupted `cap` value and may create out-of-bounds slices, leading to UB. This behavior is observable in release builds (integer overflow wraps), whereas debug builds panic due to overflow checks. ## PoC ```rs use bytes::*; fn main() { let mut a = BytesMut::from(&b"hello world"[..]); let mut b = a.split_off(5); // Ensure b becomes the unique owner of the backing storage drop(a); // Trigger overflow in new_cap + offset inside reserve b.reserve(usize::MAX - 6); // This call relies on the corrupted cap and may cause UB & HBO b.put_u8(b'h'); } ``` # Workarounds Users of `BytesMut::reserve` are only affected if integer overflow checks are configured to wrap. When integer overflow is configured to panic, this issue does not apply.
- Products
- bytes
- Affected versions
- Not specified
- Fixed versions
- 1.11.1
- CVEs
- CVE-2026-25541
- Confirmed fixed CVEs
- Not specified
- Updated in this feed
- 30 Oct 2026, 08:43 UTC · Revision 1
Source evidence
In the unique reclaim path of `BytesMut::reserve`, the condition ```rs if v_capacity >= new_cap + offset ``` uses an unchecked addition. When `new_cap + offset` overflows `usize` in release builds, this condition may incorrectly pass, causing `self.cap` to be set to a value that exceeds the actual allocated capacity. Subsequent APIs such as `spare_capacity_mut()` then trust this corrupted `cap` value and may create out-of-bounds slices, leading to UB. This behavior is observable in release builds (integer overflow wraps), whereas debug builds panic due to overflow checks. ## PoC ```rs use bytes::*; fn main() { let mut a = BytesMut::from(&b"hello world"[..]); let mut b = a.split_off(5); // Ensure b becomes the unique owner of the backing storage drop(a); // Trigger overflow in new_cap + offset inside reserve b.reserve(usize::MAX - 6); // This call relies on the corrupted cap and may cause UB & HBO b.put_u8(b'h'); } ``` # Workarounds Users of `BytesMut::reserve` are only affected if integer overflow checks are configured to wrap. When integer overflow is configured to panic, this issue does not apply.
osv:RUSTSEC-2026-0007
bytes
Fixed versions: 1.11.1
Complete source record
{
"id": "90cb0b4e5f511cd9d7684a30c949bec38d650b8b1e6c7e7e32f1d20e5a4ede64",
"url": "https://osv.dev/vulnerability/RUSTSEC-2026-0007",
"method": "structured",
"payload": {
"kind": "advisory",
"title": "Integer overflow in `BytesMut::reserve`",
"summary": "In the unique reclaim path of `BytesMut::reserve`, the condition ```rs if v_capacity >= new_cap + offset ``` uses an unchecked addition. When `new_cap + offset` overflows `usize` in release builds, this condition may incorrectly pass, causing `self.cap` to be set to a value that exceeds the actual allocated capacity. Subsequent APIs such as `spare_capacity_mut()` then trust this corrupted `cap` value and may create out-of-bounds slices, leading to UB. This behavior is observable in release builds (integer overflow wraps), whereas debug builds panic due to overflow checks. ## PoC ```rs use bytes::*; fn main() { let mut a = BytesMut::from(&b\"hello world\"[..]); let mut b = a.split_off(5); // Ensure b becomes the unique owner of the backing storage drop(a); // Trigger overflow in new_cap + offset inside reserve b.reserve(usize::MAX - 6); // This call relies on the corrupted cap and may cause UB & HBO b.put_u8(b'h'); } ``` # Workarounds Users of `BytesMut::reserve` are only affected if integer overflow checks are configured to wrap. When integer overflow is configured to panic, this issue does not apply.",
"evidence": "osv:RUSTSEC-2026-0007",
"products": [
{
"name": {
"value": "bytes",
"evidence": "/affected/0/package/name"
},
"prerequisites": [],
"fixed_versions": [
{
"value": "1.11.1",
"evidence": "/affected/0/ranges"
}
],
"affected_versions": []
}
],
"severity": "unknown",
"structured": {
"id": "RUSTSEC-2026-0007",
"aliases": [
"CVE-2026-25541",
"GHSA-434x-w66g-qw3r",
"RUSTSEC-2026-0007"
],
"affected": [
{
"ranges": [
{
"type": "SEMVER",
"events": [
{
"introduced": "1.2.1"
},
{
"fixed": "1.11.1"
}
]
}
],
"package": {
"name": "bytes",
"purl": "pkg:cargo/bytes",
"ecosystem": "crates.io"
},
"database_specific": {
"cvss": null,
"source": "https://github.com/rustsec/advisory-db/blob/osv/crates/RUSTSEC-2026-0007.json",
"categories": [
"memory-corruption"
],
"informational": null
},
"ecosystem_specific": {
"affects": {
"os": [],
"arch": [],
"functions": []
},
"affected_functions": null
}
}
],
"modified": "2026-10-12T18:00:09.239418978Z",
"provider": "osv",
"references": [
"https://crates.io/crates/bytes",
"https://rustsec.org/advisories/RUSTSEC-2026-0007.html",
"https://github.com/tokio-rs/bytes/commit/d0293b0e35838123c51ca5dfdf468ecafee4398f"
],
"provider_metadata": {
"license": "CC-BY-4.0"
}
},
"related_cves": [
{
"value": "CVE-2026-25541",
"evidence": "/aliases"
}
],
"security_relevant": true,
"severity_evidence": null
},
"source_id": "core-osv",
"document_id": 306398,
"published_at": "2026-02-03T12:00:00+00:00"
}