Type Confusion Vulnerability in enum-map Package: Enum Trait Implementation Flaw
Summary
RUSTSEC-2026-0218: Enum trait allows type confusion when manually implemented. Affects enum-map versions >= 3.0.0-0.gat.0, < 3.1.0. Fixed in 3.1.0. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
The enum-map package is a Rust library designed to facilitate the creation and manipulation of enumerated maps, allowing developers to associate values with enum variants efficiently. It leverages Rust's type system to ensure safety and performance. However, a flaw in the implementation of the Enum trait can lead to severe type confusion, compromising the integrity of the application using this library.
Vulnerability Detail
The vulnerability arises from the enum-map package's Enum trait, which did not enforce that the element type of the Array associated type must match the array's generic parameter V. This oversight allows developers to implement the Enum trait in a way that leads to type confusion, potentially resulting in memory corruption. For instance, a manual implementation could declare an Array<V> with elements that are not of type V, leading to unpredictable behavior and security risks.
How To Fix
Minimum fixed version
3.1.0
This is the first release that contains the fix.
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
As a temporary workaround, avoid manually implementing the Enum trait in a way that does not adhere to the expected type constraints. Ensure that any custom implementations maintain type consistency with the generic parameter V. For example, do not implement the Enum trait like this:
struct IntentionallyWrong;
impl Enum for IntentionallyWrong {
type Array<V> = [String; 4];
fn from_usize(_: usize) -> Self {
IntentionallyWrong
}
fn into_usize(self) -> usize {
0
}
}
Conclusion
The enum-map package contains a critical vulnerability related to the Enum trait implementation that can lead to type confusion and memory corruption. It is essential to update to version 3.1.0 or later to mitigate this risk. Additionally, developers should be cautious when implementing the Enum trait to ensure type safety.
See every vulnerability recorded for enum-map →
FAQ
The enum-map package is a Rust library that allows developers to create maps indexed by enum variants, providing a type-safe way to associate values with enums.
The vulnerability is a type confusion issue in the Enum trait implementation, which can lead to memory corruption when the associated types do not match.
You can use Vulert, a tool that monitors and alerts for open-source vulnerabilities in real-time. Visit Vulert Scanner to check your application without any signup.
If exploited, this vulnerability can lead to unpredictable behavior, crashes, or even security breaches due to memory corruption.
Update your Cargo.toml file to specify version 3.1.0 or later and run 'cargo update' to apply the changes.
Related vulnerabilities
Recent vulnerabilities recorded for enum-map.