GHSA-2jx3-ff3v-j7jj: yara-x Unvalidated Deserialization Vulnerability

MODERATE
CWE-502
Published
Advisory Summary

GHSA-2jx3-ff3v-j7jj is a MODERATE unvalidated deserialization vulnerability (CWE-502: Deserialization of Untrusted Data) affecting yara-x libraries in the crates.io ecosystem. The issue involves unvalidated deserialization in safe `rules::deserialize` allows memory corruption and ub. Remediation is available by upgrading affected packages to version 1.19.0.

GHSA-2jx3-ff3v-j7jj at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-2jx3-ff3v-j7jj
Severity MODERATE
CVSS v3.1 Base Score N/A
CWE Classification CWE-502: Deserialization of Untrusted Data
Affected Product yara-x
Package Ecosystem crates.io
Published Date
Last Updated

How to Fix GHSA-2jx3-ff3v-j7jj

To remediate this vulnerability, upgrade all affected yara-x dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

yara-x fixed: 1.19.0
Upgrade yara-x to 1.19.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for yara-x

How to Check if You Are Affected

To determine whether your application is affected by GHSA-2jx3-ff3v-j7jj, inspect your project dependencies for yara-x:

inspect dependencies for yara-x

Analyze the terminal output to locate any version of yara-x in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.19.0), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-502: Deserialization of Untrusted Data, where the product deserializes untrusted data without sufficiently ensuring that the resulting data will be valid. In yara-x, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

> [!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 crashing_payload.bin where only a single byte in the structural metadata tail is mutated (changing a `SubPatternId` from `1` to `248` while keeping the WebAssembly bytecode completely untouched and valid). Below is the self-contained verification script which compiles and runs against the official **unmodified** `yara-x v1.17.0` crate: ```rust use yara_x::{Rules, Scanner}; fn main() { // Embed the crashing payload generated by the fuzzer at compile time. let serialized = include_bytes!("crashing_payload.bin"); println!("Loaded embedded crashing payload, length: {}", serialized.len()); // Deserialize. On unmodified library, this succeeds because the WASM and headers // are pristine and structural corruption isn't validated. if let Ok(deserialized) = Rules::deserialize(serialized) { println!("Deserialization succeeded! Running scanner..."); let mut scanner = Scanner::new(&deserialized); // Run the standard scan, which will execute the WASM and trigger the out-of-bounds read! let _ = scanner.scan(b"lorem ipsum dolor sit amet"); println!("Scanner finished."); } else { println!("Deserialization failed!"); } } ``` ### 1. Miri Trace NOTE: This needs to be run with 1.17.0. I haven't tested this against other versions. Unfortunately I was able to get a miri trace, but I'm not able to reproduce it right now because of lockfile changes. If you're trying this out be sure to use `MIRIFLAGS="-Zmiri-disable-stacked-borrows"` ### 2. Segfault / panics When run natively (without Miri or any sanitizers) on a standard Linux platform, the process immediately segfaults: ```bash $ cargo run --bin verify Loaded embedded crashing payload, length: 11777 Deserialization succeeded! Running scanner... Segmentation fault (core dumped) ``` And with a newer compiler (which appears to have debug assertions in `get_unchecked)` ```bash Deserialization succeeded! Running scanner... thread 'main' (997442) panicked at lib/src/compiler/rules.rs:404:36: unsafe precondition(s) violated: slice::get_unchecked requires that the index is within the slice This indicates a bug in the program. This Undefined Behavior check is optional, and cannot be relied on for safety. note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` </details> <details><summary>Suggested Fix</summary> To uphold Rust soundness guarantees, either mark `Rules::deserialize` as `pub unsafe fn deserialize` with a formal `/// # Safety` contract documenting that callers are responsible for verifying the authenticity and structural integrity of the input bytes (e.g. via cryptographic signatures), or replace all internal `get_unchecked` and `to_str_unchecked` calls on deserialized data structures with safe bounds checks (`.get()`) and UTF-8 validation (`std::str::from_utf8`). </details> ---

GHSA-2jx3-ff3v-j7jj Affected yara-x Versions

1 component(s)
Fixed Versions:
1.19.0
Product / Package Ecosystem Affected Versions Fixed Version
yara-x
crates.io
< 1.19.0
1.19.0

References

Frequently Asked Questions

What is GHSA-2jx3-ff3v-j7jj?
GHSA-2jx3-ff3v-j7jj is a security vulnerability in yara-x involving Unvalidated deserialization in safe `Rules::deserialize` allows memory corruption and UB under CWE-502: Deserialization of Untrusted Data.
Which yara-x versions are affected?
Affected versions include releases prior to 1.19.0 across affected packages: yara-x.
What version fixes GHSA-2jx3-ff3v-j7jj?
Upgrading to 1.19.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is yara-x affected?
Yes, yara-x is affected in releases prior to 1.19.0. Upgrade your dependency to 1.19.0 or later.
What CWE is associated with GHSA-2jx3-ff3v-j7jj?
GHSA-2jx3-ff3v-j7jj is classified under CWE-502: Deserialization of Untrusted Data (The product deserializes untrusted data without sufficiently ensuring that the resulting data will be valid.).
How can I check crates.io dependencies for GHSA-2jx3-ff3v-j7jj?
Run the dependency tree command: 'inspect dependencies for yara-x'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-2jx3-ff3v-j7jj",
  "modified" : "2026-09-24T19:09:28Z",
  "published" : "2026-09-24T19:09:28Z",
  "aliases" : [ ],
  "summary" : "yara-x: Unvalidated deserialization in safe `Rules::deserialize` allows memory corruption and UB",
  "details" : "> [!NOTE]\n> This finding was identified during an agentic unsafe Rust code review performed by Gemini AI, followed by human review and verification.\n\n\n## The Issue\n\nThe 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`.\n\nThis 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:\n\n- `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).\n\nhttps://github.com/VirusTotal/yara-x/blob/5bd1f35db783679c90a3ea1a66bd15fe4e55bef1/lib/src/compiler/rules.rs#L355-L360\n\n\n- `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).\n\nhttps://github.com/VirusTotal/yara-x/blob/5bd1f35db783679c90a3ea1a66bd15fe4e55bef1/lib/src/models.rs#L204-L210\n\nBecause 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.\n\n\n<details><summary>Minimal Reproduction (Miri / Native Crash)</summary>\n\nZip file with crashing_payload: \n[crashing_payload.zip](https://github.com/user-attachments/files/29173221/crashing_payload.zip)\n\nWe have a payload crashing_payload.bin where only a single byte in the structural metadata tail is mutated (changing a `SubPatternId` from `1` to `248` while keeping the WebAssembly bytecode completely untouched and valid).\n\nBelow is the self-contained verification script which compiles and runs against the official **unmodified** `yara-x v1.17.0` crate:\n\n```rust\nuse yara_x::{Rules, Scanner};\n\nfn main() {\n    // Embed the crashing payload generated by the fuzzer at compile time.\n    let serialized = include_bytes!(\"crashing_payload.bin\");\n    println!(\"Loaded embedded crashing payload, length: {}\", serialized.len());\n\n    // Deserialize. On unmodified library, this succeeds because the WASM and headers\n    // are pristine and structural corruption isn't validated.\n    if let Ok(deserialized) = Rules::deserialize(serialized) {\n        println!(\"Deserialization succeeded! Running scanner...\");\n        let mut scanner = Scanner::new(&deserialized);\n        \n        // Run the standard scan, which will execute the WASM and trigger the out-of-bounds read!\n        let _ = scanner.scan(b\"lorem ipsum dolor sit amet\");\n        println!(\"Scanner finished.\");\n    } else {\n        println!(\"Deserialization failed!\");\n    }\n}\n```\n\n### 1. Miri Trace\n\nNOTE: This needs to be run with 1.17.0. I haven't tested this against other versions.\n\n\nUnfortunately I was able to get a miri trace, but I'm not able to reproduce it right now because of lockfile changes. If you're trying this out be sure to use `MIRIFLAGS=\"-Zmiri-disable-stacked-borrows\"`\n\n\n### 2. Segfault / panics\n\nWhen run natively (without Miri or any sanitizers) on a standard Linux platform, the process immediately segfaults:\n\n```bash\n$ cargo run --bin verify\nLoaded embedded crashing payload, length: 11777\nDeserialization succeeded! Running scanner...\nSegmentation fault (core dumped)\n```\n\nAnd with a newer compiler (which appears to have debug assertions in `get_unchecked)`\n\n\n```bash\nDeserialization succeeded! Running scanner...\n\nthread 'main' (997442) panicked at lib/src/compiler/rules.rs:404:36:\nunsafe precondition(s) violated: slice::get_unchecked requires that the index is within the slice\n\nThis indicates a bug in the program. This Undefined Behavior check is optional, and cannot be relied on for safety.\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n```\n\n</details>\n\n\n<details><summary>Suggested Fix</summary>\n\nTo uphold Rust soundness guarantees, either mark `Rules::deserialize` as `pub unsafe fn deserialize` with a formal `/// # Safety` contract documenting that callers are responsible for verifying the authenticity and structural integrity of the input bytes (e.g. via cryptographic signatures), or replace all internal `get_unchecked` and `to_str_unchecked` calls on deserialized data structures with safe bounds checks (`.get()`) and UTF-8 validation (`std::str::from_utf8`).\n\n</details>\n\n---",
  "severity" : [ {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:L/AC:L/AT:N/PR:L/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "crates.io",
      "name" : "yara-x"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.19.0"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 1.18.0"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/VirusTotal/yara-x/security/advisories/GHSA-2jx3-ff3v-j7jj"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/VirusTotal/yara-x/commit/25efa375572efcfbe880a263ee3b0932d4b61a24"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/VirusTotal/yara-x"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/VirusTotal/yara-x/releases/tag/v1.19.0"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-502" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-09-24T19:09:28Z",
    "nvd_published_at" : null
  }
}