Email me

Rust advisories / enumflags2

Unsound MediumRUSTSEC-2023-0035 · enumflags2

RUSTSEC-2023-0035: Adverserial use of `make_bitflags!` macro can cause undefined behavior

Short answerenumflags2 has an API that can cause undefined behaviour from safe code: Adverserial use of `make_bitflags!` macro can cause undefined behavior. Fixed in 0.7.7.

Crateenumflags2
TypeUnsound
Affected versionsFrom 0.7.0 before 0.7.7.
Fixed in0.7.7
SeverityMedium (GitHub rating)
Published2023-04-17
Last changed2023-11-08
Also known asGHSA-qvc4-78gw-pv8p

What to do

  1. See which version you have: cargo tree -i enumflags2 (it also shows which of your dependencies pulls it in).
  2. Update within your version requirement: cargo update -p enumflags2. If the fix is a newer major or minor than your requirement allows, raise it in Cargo.toml (for example enumflags2 = "0.7.7") or update the dependency that pulls it in.
  3. Check again with cargo audit, or paste your Cargo.lock into our Cargo.toml checker.

Details from the advisory

The macro relied on an expression of the form Enum::Variant always being a variant of the enum. However, it may also be an associated integer constant, in which case there's no guarantee that the value of said constant consists only of bits valid for this bitflag type.

Thus, code like this could create an invalid BitFlags<Test>, which would cause iterating over it to trigger undefined behavior. As the debug formatter internally iterates over the value, it is also affected.

use enumflags2::{bitflags, make_bitflags};

#[bitflags]
#[repr(u8)]
#[derive(Copy, Clone, Debug)]
enum Test {
    A = 1,
    B = 2,
}

impl Test {
    const C: u8 = 69;
}

fn main() {
    let x = make_bitflags!(Test::{C});
    // printing or iterating over x is UB
}

References

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

Same crateenumflags2: security historyEvery advisory for this crate, and whether it is safe to use today.Read it next →

Did this answer your question?

Get the receipts by email.

What my AI agents tried this week, with the real numbers: what worked, what flopped, what made money. One email when there is something worth reading.

No spam, never sold. Every email has a one-click unsubscribe.

Popular in the shop

All 124 tools →

Browse: Bundles and kitsHome, family and schoolMoney and businessAI toolsSports and fitnessMaking and hobbiesFood and drinkIndie dev and launchTrading and quant

Free: Landing page teardown iPhone app cost calculator LLM API cost calculator Paid online: $49 Launch Check App builds Articles FAQ