[ { "id": "RUSTSEC-2026-0218", "modified": "2026-07-28T18:34:53Z", "published": "2026-07-21T12:00:00Z", "aliases": [], "related": [], "summary": "`Enum` trait allows type confusion when manually implemented", "details": "Affected versions of this crate did not require the element type of the `Array` associated type in the `Enum` trait to match the array's generic parameter `V`.\n\nThis can result in type confusion, and consequently memory corruption, when a manual `Enum` implementation declares an `Array` whose elements are not actually of type `V`:\n\n```rust\nstruct IntentionallyWrong;\n\nimpl Enum for IntentionallyWrong {\n type Array = [String; 4];\n\n fn from_usize(_: usize) -> Self {\n IntentionallyWrong\n }\n\n fn into_usize(self) -> usize {\n 0\n }\n}\n\nenum_map! { IntentionallyWrong => 42 };\n```\n\nThe flaw was corrected in commit [7a8b815432](https://codeberg.org/sugar700/enum-map/commit/7a8b8154323d426415a10accf104cd05c394cda9) by adding a `Value = V` bound to the `Array` type in the `Enum` trait.", "severity": [], "affected": [ { "package": { "ecosystem": "crates.io", "name": "enum-map", "purl": "pkg:cargo/enum-map" }, "ecosystem_specific": { "affects": { "arch": [], "os": [], "functions": [] }, "affected_functions": null }, "database_specific": { "categories": [ "memory-corruption" ], "cvss": null, "informational": "unsound" }, "ranges": [ { "type": "SEMVER", "events": [ { "introduced": "3.0.0-0.gat.0" }, { "fixed": "3.1.0" } ] } ], "versions": [] } ], "references": [ { "type": "PACKAGE", "url": "https://crates.io/crates/enum-map" }, { "type": "ADVISORY", "url": "https://rustsec.org/advisories/RUSTSEC-2026-0218.html" }, { "type": "WEB", "url": "https://codeberg.org/sugar700/enum-map/src/branch/master/CHANGELOG.md#version-310" }, { "type": "REPORT", "url": "https://github.com/rustsec/advisory-db/issues/3060" } ], "database_specific": { "license": "CC0-1.0" } }, { "id": "RUSTSEC-2022-0010", "modified": "2023-06-13T13:10:24Z", "published": "2022-02-17T12:00:00Z", "aliases": [ "GHSA-rxhx-9fj6-6h2m" ], "related": [], "summary": "enum_map macro can cause UB when `Enum` trait is incorrectly implemented", "details": "Affected versions of this crate did not properly check the length of an enum when using `enum_map!` macro, trusting user-provided length.\n\nWhen the `LENGTH` in the `Enum` trait does not match the array length in the `EnumArray` trait, this can result in the initialization of the enum map with uninitialized types, which in turn can allow an attacker to execute arbitrary code.\n\nThis problem can only occur with a manual implementation of the Enum trait, it will never occur for enums that use `#[derive(Enum)]`.\n\nExample code that triggers this vulnerability looks like this:\n\n```rust\nenum E {\n A,\n B,\n C,\n}\n\nimpl Enum for E {\n const LENGTH: usize = 2;\n\n fn from_usize(value: usize) -> E {\n match value {\n 0 => E::A,\n 1 => E::B,\n 2 => E::C,\n _ => unimplemented!(),\n }\n }\n\n fn into_usize(self) -> usize {\n self as usize\n }\n}\n\nimpl EnumArray for E {\n type Array = [V; 3];\n}\n\nlet _map: EnumMap = enum_map! { _ => \"Hello, world!\".into() };\n```\n\nThe flaw was corrected in commit [b824e23](https://gitlab.com/KonradBorowski/enum-map/-/commit/b824e232f2fb47837740070096ac253df8e80dfc) by putting `LENGTH` property on sealed trait for macro to read.", "severity": [], "affected": [ { "package": { "ecosystem": "crates.io", "name": "enum-map", "purl": "pkg:cargo/enum-map" }, "ecosystem_specific": { "affects": { "arch": [], "os": [], "functions": [] }, "affected_functions": null }, "database_specific": { "categories": [ "code-execution", "memory-corruption", "memory-exposure" ], "cvss": null, "informational": "unsound" }, "ranges": [ { "type": "SEMVER", "events": [ { "introduced": "2.0.0-2" }, { "fixed": "2.0.2" } ] } ], "versions": [] } ], "references": [ { "type": "PACKAGE", "url": "https://crates.io/crates/enum-map" }, { "type": "ADVISORY", "url": "https://rustsec.org/advisories/RUSTSEC-2022-0010.html" }, { "type": "WEB", "url": "https://gitlab.com/KonradBorowski/enum-map/-/blob/master/CHANGELOG.md#version-202" } ], "database_specific": { "license": "CC0-1.0" } } ]