GHSA-2jx3-ff3v-j7jj: Rust/yara-x vulnerability

Published Sep 24, 2026
·
Updated

[!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 accepting any generic byte sequence B: AsRef<[u8]>. It restores compiled rule structures directly from raw bytes using bincode::serde::decodefromslice.

This decoded Rules struct contains internal lookup tables, including subpatterns: Vec<(PatternId, SubPattern)>, atoms: Vec<SubPatternAtom>, and litpool: BStringPool. Subsequent safe operations assume these internal tables satisfy strict structural invariants:

- Rules::getsubpattern executes unsafe { self.subpatterns.getunchecked(subpatternid.0 as usize) }. If untrusted serialized bytes contain an atom referencing an out-of-bounds SubPatternId, calling getsubpattern 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.tostrunchecked() }. If serialized bytes corrupt litpool indices or structural data, tostrunchecked 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 crashingpayload: crashingpayload.zip

We have a payload crashingpayload.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 yarax::{Rules, Scanner};

fn main() { // Embed the crashing payload generated by the fuzzer at compile time. let serialized = includebytes!("crashingpayload.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 getunchecked)

bash Deserialization succeeded! Running scanner...

thread 'main' (997442) panicked at lib/src/compiler/rules.rs:404:36: unsafe precondition(s) violated: slice::getunchecked 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 RUSTBACKTRACE=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 getunchecked and tostrunchecked calls on deserialized data structures with safe bounds checks (.get()) and UTF-8 validation (std::str::fromutf8).

</details>

---

Affected Software

1 affected componentFixes available
rust/yara-x<=1.18.0
1.19.0

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade rust/yara-x to a version that resolves this vulnerability.

    Fixed in 1.19.0
  2. Compensating control

    Change Rules::deserialize to a public unsafe function and document a formal safety contract requiring callers to verify the authenticity and structural integrity of serialized input bytes, such as via cryptographic signatures.

  3. Compensating control

    Replace unchecked access for deserialized data with safe validation: use .get() instead of get_unchecked() for sub-pattern and table indices, and use std::str::from_utf8 instead of to_str_unchecked() so malformed indices and invalid UTF-8 are rejected safely.

Event History

Sep 24, 2026
Advisory Published
via GitHub·07:09 PM
Data Sourced
via GitHub·07:09 PM
DescriptionWeaknessAffected Software

Frequently Asked Questions

1

What conditions are required for exploitation?

An attacker must be able to supply serialized rule bytes to the public safe Rules::deserialize API. The deserialized rules must then be used in scanning or another operation that resolves a malformed atom's SubPatternId.

2

Which deployments are exposed?

Deployments are exposed when they deserialize rule data from an untrusted source. Applications that only deserialize trusted, internally generated compiled rules do not give an attacker a direct path to provide the malformed serialized data.

3

What is the impact of malformed serialized rules?

A malformed atom can reference a SubPatternId outside the sub-pattern table. Later access through get_sub_pattern uses unchecked indexing, causing an out-of-bounds memory read and undefined behavior.

4

What can be done before updating?

Do not pass untrusted serialized rule bytes to Rules::deserialize. Restrict serialized rule inputs to trusted sources and avoid scanning rules deserialized from attacker-controlled data.

5

How can I identify a relevant code path?

Look for calls to Rules::deserialize that accept bytes obtained from users, network services, shared storage, or other untrusted producers, and determine whether the resulting Rules object is subsequently used for scanning. The advisory references an update in the v1.19.0 release.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203