mediumVulnerability

GHSA-2jx3-ff3v-j7jj

> [!NOTE] > This finding was identified during an agentic unsafe Rust code review performed by Gemini AI, followed by human review and verification. ## The Issue The crate exports a public safe API [`Rules::deserialize`](https://github.com/VirusTotal/yara-x/blob/5bd1f35db783679c90a3ea1a66bd15fe4e55bef1/lib/src/compiler/rules.rs#L187-L254) accepting any generic byte sequence `B: AsRef<[u8]>`. It restores compiled rule structures directly from raw bytes using `bincode::serde::decode_from_slice`. This decoded `Rules` struct contains internal lookup tables, including `sub_patterns: Vec<(PatternId, SubPattern)>`, `atoms: Vec<SubPatternAtom>`, and `lit_pool: BStringPool`. Subsequent safe operations assume these internal tables satisfy strict structural invariants: - `Rules::get_sub_pattern` executes `unsafe { self.sub_patterns.get_unchecked(sub_pattern_id.0 as usize) }`. If untrusted serialized bytes contain an atom referencing an out-of-bounds `SubPatternId`, calling `get_sub_pattern` during scanning triggers an out-of-bounds memory read (Undefined Behavior). https://github.com/VirusTotal/yara-x/blob/5bd1f35db783679c90a3ea1a66bd15fe4e55bef1/lib/src/compiler/rules.rs#L355-L360 - `Metadata::next()` extracts string metadata via `unsafe { s.to_str_unchecked() }`. If serialized bytes corrupt `lit_pool` indices or structural data, `to_str_unchecked` constructs a `&str` pointing to invalid UTF-8 bytes (Undefined Behavior). https://github.com/VirusTotal/yara-x/blob/5bd1f35db783679c90a3ea1a66bd15fe4e55bef1/lib/src/models.rs#L204-L210 Because passing malformed or untrusted data to `Rules::deserialize` induces Undefined Behavior in subsequent safe calls (`Scanner::new`, `Scanner::scan`) without any `unsafe` blocks in caller code, this API is unsound. <details><summary>Minimal Reproduction (Miri / Native Crash)</summary> Zip file with crashing_payload: [crashing_payload.zip](https://github.com/user-attachments/files/29173221/crashing_payload.zip) We have a payload cr

Properties

ghsa_id
GHSA-2jx3-ff3v-j7jj
severity
medium
summary
yara-x: Unvalidated deserialization in safe `Rules::deserialize` allows memory corruption and UB
last_source
GitHub Advisory Database
cve_id
GHSA-2jx3-ff3v-j7jj
signal_observed_at
2026-09-25T06:02:49+00:00
is_ghsa_only
true
retrieved_at
2026-09-25T06:02:49+00:00
ghsa_published
2026-09-24T19:09:28Z
source_url
https://github.com/advisories/GHSA-2jx3-ff3v-j7jj
ghsa_updated
2026-09-24T19:09:29Z

Related Entities (4)

REPORTED_BY (1)

→[Source]GitHub Advisory Database

VULNERABLE_TO (1)

←[Software]rust/yara-x

AFFECTS (1)

→[Software]rust/yara-x

HAS_WEAKNESS (1)

→[Weakness]Deserialization of Untrusted Data

Explore deeper with Ninja Signal's threat intelligence graph

GHSA-2jx3-ff3v-j7jj — Ninja Signal Threat Intelligence | Ninja Signal