Skip to content
Heist/ feed
Back to feed
Medium

BTreeMap memory leak when deallocating nodes with overflows

Type: advisorySources: OSV

When storing unbounded types in a BTreeMap, a node is represented as a linked list of "memory chunks". It was discovered recently that when we deallocate a node, in some cases 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 #212 https://github.com/dfinity/stable-structures/pull/212 by changing the logic for deallocating nodes to ensure that all of a node's memory chunks are deallocated and users are asked to upgrade to version 0.6.4.. Tests have been added to prevent regressions of this nature moving forward. Note: Users of stable-structure < 0.6.0 are not affected. 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.

Products
Not specified
Affected versions
Not specified
Fixed versions
Not specified
CVEs
CVE-2024-4435
Confirmed fixed CVEs
Not specified
Updated in this feed
4 Nov 2026, 03:09 UTC · Revision 1

Source evidence

BTreeMap memory leak when deallocating nodes with overflows

core-osv · Original source

Published 21 May 2024, 09:41 UTC

When storing unbounded types in a BTreeMap, a node is represented as a linked list of "memory chunks". It was discovered recently that when we deallocate a node, in some cases 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 #212 https://github.com/dfinity/stable-structures/pull/212 by changing the logic for deallocating nodes to ensure that all of a node's memory chunks are deallocated and users are asked to upgrade to version 0.6.4.. Tests have been added to prevent regressions of this nature moving forward. Note: Users of stable-structure < 0.6.0 are not affected. 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.

osv:CVE-2024-4435
Complete source record
{
  "id": "92b2b16e1a5b3775a992b205a3cd2d8a8a540a923b37a6fe2e10f589ff72c0a3",
  "url": "https://osv.dev/vulnerability/CVE-2024-4435",
  "method": "structured",
  "payload": {
    "kind": "advisory",
    "title": "BTreeMap memory leak when deallocating nodes with overflows",
    "summary": "When storing unbounded types in a BTreeMap, a node is represented as a linked list of \"memory chunks\". It was discovered recently that when we deallocate a node, in some cases 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 #212 https://github.com/dfinity/stable-structures/pull/212 by changing the logic for deallocating nodes to ensure that all of a node's memory chunks are deallocated and users are asked to upgrade to version 0.6.4.. Tests have been added to prevent regressions of this nature moving forward. Note: Users of stable-structure < 0.6.0 are not affected. 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.",
    "evidence": "osv:CVE-2024-4435",
    "products": [],
    "severity": "medium",
    "structured": {
      "id": "CVE-2024-4435",
      "aliases": [
        "CVE-2024-4435",
        "GHSA-3rcq-39xp-7xjp",
        "RUSTSEC-2024-0406"
      ],
      "metrics": [
        {
          "type": "CVSS_V3",
          "score": "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:H"
        }
      ],
      "affected": [
        {
          "ranges": [
            {
              "repo": "https://github.com/dfinity/stable-structures",
              "type": "GIT",
              "events": [
                {
                  "introduced": "f9483a1da395a9f8a95f6bee60e8b19ff4601291"
                },
                {
                  "fixed": "206fc047acbca253d849a3ececb2e9f934dbcc45"
                }
              ],
              "database_specific": {
                "extracted_events": [
                  {
                    "range": [
                      {
                        "introduced": "0.6.0"
                      },
                      {
                        "fixed": "0.6.4"
                      }
                    ],
                    "source": "AFFECTED_FIELD",
                    "strategy": "StandardRange"
                  },
                  {
                    "cpe": "cpe:2.3:a:dfinity:stable_structures:*:*:*:*:*:rust:*:*",
                    "range": [
                      {
                        "introduced": "0"
                      },
                      {
                        "fixed": "0.6.0"
                      }
                    ],
                    "source": "CPE_RANGE"
                  }
                ]
              }
            }
          ],
          "versions": [
            "v0.6.3",
            "v0.6.2",
            "v0.6.1",
            "v0.6.0"
          ],
          "database_specific": {
            "source": "https://storage.googleapis.com/cve-osv-conversion/osv-output/CVE-2024-4435.json"
          }
        }
      ],
      "modified": "2026-10-28T02:30:32.779849988Z",
      "provider": "osv",
      "references": [
        "https://crates.io/crates/ic-stable-structures",
        "https://docs.rs/ic-stable-structures/0.6.4/ic_stable_structures/",
        "https://internetcomputer.org/docs/current/developer-docs/smart-contracts/maintain/storage#stable-memory",
        "https://github.com/CVEProject/cvelistV5/tree/main/cves/2024/4xxx/CVE-2024-4435.json",
        "https://nvd.nist.gov/vuln/detail/CVE-2024-4435",
        "https://github.com/dfinity/stable-structures/pull/212",
        "https://github.com/dfinity/stable-structures"
      ],
      "provider_metadata": {
        "cwe_ids": [
          "CWE-401"
        ],
        "cna_assigner": "Dfinity",
        "osv_generated_from": "https://github.com/CVEProject/cvelistV5/tree/main/cves/2024/4xxx/CVE-2024-4435.json"
      }
    },
    "related_cves": [
      {
        "value": "CVE-2024-4435",
        "evidence": "/id"
      }
    ],
    "security_relevant": true,
    "severity_evidence": "/severity/0/score"
  },
  "source_id": "core-osv",
  "document_id": 499941,
  "published_at": "2024-05-21T09:41:35.242+00:00"
}