Rust advisories / ic-stable-structures
Vulnerability MediumRUSTSEC-2024-0406 · ic-stable-structures
RUSTSEC-2024-0406: BTreeMap memory leak when deallocating nodes with overflows
Short answerA security vulnerability in the ic-stable-structures crate: BTreeMap memory leak when deallocating nodes with overflows. Medium severity (CVSS 5.9). Fixed in 0.6.4: update to a fixed version.
| Crate | ic-stable-structures |
|---|---|
| Type | Vulnerability (denial-of-service) |
| Affected versions | From 0.6.0 before 0.6.4. |
| Fixed in | 0.6.4 |
| Severity | Medium, CVSS 5.9 CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:H |
| Published | 2024-05-17 |
| Last changed | 2024-12-04 |
| Also known as | CVE-2024-4435, GHSA-3rcq-39xp-7xjp |
What to do
- See which version you have:
cargo tree -i ic-stable-structures(it also shows which of your dependencies pulls it in). - Update within your version requirement:
cargo update -p ic-stable-structures. If the fix is a newer major or minor than your requirement allows, raise it in Cargo.toml (for exampleic-stable-structures = "0.6.4") or update the dependency that pulls it in. - Check again with
cargo audit, or paste your Cargo.lock into our Cargo.toml checker.
Details from the advisory
When storing unbounded types in a BTreeMap, a node is represented as a linked list of "memory chunks". In some cases, when we deallocate a node only the first memory chunk is deallocated, and the rest of the memory chunks remain (incorrectly) allocated, causing a memory leak.
In the worst case, depending on how a canister uses the BTreeMap, an adversary could interact with the canister through its API and trigger interactions with the map that keep consuming memory due to the memory leak. This could potentially lead to using an excessive amount of memory, or even running out of memory.
This issue has been fixed in dfinity/stable-structures/pull/212 by changing the logic for deallocating nodes to ensure that all of a node's memory chunks are deallocated. Tests have been added to prevent regressions of this nature moving forward.
**Note:** Users of stable-structure < 0.6.0 are not affected.
Workarounds
Users who are not storing unbounded types in BTreeMap are not affected and do not need to upgrade. Otherwise, an upgrade to version 0.6.4 is necessary.
References
- GitHub Security Advisory (GHSA-3rcq-39xp-7xjp)
- dfinity/stable-structures/pull/212
- Stable Structures Documentation
- Stable Memory on the Internet Computer
References
- Package: crates.io/crates/ic-stable-structures
- Advisory: rustsec.org/advisories/RUSTSEC-2024-0406.html
- Web: github.com/dfinity/stable-structures/pull/212
From the RustSec Advisory Database (CC0-1.0) via the OSV export, downloaded Oct 24, 2026. Severity score computed from the published CVSS vector.
Up next
Are you affected?Check your whole dependency treePaste Cargo.lock: every advisory, for your exact versions.Read it next →Also worth your time
Did this answer your question?