Repository navigation
chore: sync upstream changes (a1d39ac4) - #188
Merged
Merged
Conversation
The table of `osabi` values documents `OSABI_FREEBSD`, but the constant is defined as `OSABI_FREE_BSD` in `elf.proto`: ```protobuf OSABI_FREE_BSD =9; ``` `OSABI_FREEBSD` appears nowhere in the codebase, so a rule written against the documented name does not compile. `OSABI_GNU_HURD`, value 4, was missing from the table, which went straight from 3 to 6. I compared every constant in each module reference against the enums in the corresponding `.proto` file. These two were the only mismatches across elf, pe, macho, dex, lnk and math, 542 constants in total, apart from `lnk` `RESERVED_1` and `RESERVED_2`, which are reserved bits and I left alone.
A post about something the blog has never covered in 19 entries, and that the last three releases were mostly about. Of the 61 entries in the release notes for 1.23.0, 1.24.0 and 1.25.0, 45 are bug fixes, and 21 of those 45 are specifically about surviving input built to break the scanner rather than to be scanned. That work is currently visible only to people who read release notes. The post does not retell it as a list of fixed bugs. It answers the question someone has when they put YARA-X behind a service: which of these inputs can I accept from someone else? There are three, and they get three different answers. 1. **The scanned file is hostile, and the engine assumes it.** The hardening of eight module parsers in 1.24.0, the 64 MiB cap on decompressed ZIP entries, the bounded CPU in Authenticode verification. The point being made to the reader is that pre-validating samples is not their job. 2. **Rule source is semi-trusted.** The AST depth limit, which rejects a deeply nested condition as `E001` instead of running the compiler out of stack; `E049` once atoms cross `MAX_ATOMS`; the per-pattern atom budget; and `include` confined to configured directories since 1.24.0. It also says plainly that bounding the damage is not the same as removing the cost, so compiling untrusted rules still wants a timeout. 3. **Compiled rules are trusted completely.** This is the part people get wrong. `Rules::deserialize` has documented it under `# Safety` for months, and the post quotes that text rather than paraphrasing it. The reason given is the one in the code: the embedded WASM module is parsed on load, but it is not checked against the host functions and globals it will be linked against when the scanner runs. **On section 3, since it is the one worth being careful with.** It states the rule and the reason, not a recipe. There are no reproducers, no offsets and no crash inputs, and there is no claim that this is a defect. The takeaway is one line, do not deserialize rules you did not produce, and the framing is that a `.yarc` is closer to a shared library than to data, so it belongs behind the answers that code distribution already has. I opened #922 first to ask whether you wanted this, then closed it, because describing a post is a worse way to decide than reading one. If the answer is no, closing this costs nothing. If the answer is yes with changes, the text is here to mark up. **Checked rather than asserted.** The three counts come from the release notes. The `E001` output in the post is real, from a rule bisected to find where the limit actually falls. `MAX_ATOMS_PER_REGEXP` is described as a budget and not a limit, because a pattern that would expand past it compiles fine with narrowed atoms, which I confirmed before writing the paragraph. The site builds with the Hugo version the repo installs: 102 pages, no warnings, and the post renders at `/blog/what-yara-x-assumes-about-its-inputs/` and is listed on the blog index.
The `zip` module is in `default-modules` but has no page in the module
reference.
Three modules enabled by default have no page: `cuckoo`, `vt` and `zip`.
The other two have a reason. `vt` is VirusTotal specific and is
documented in the VirusTotal documentation, and `cuckoo` does nothing
without an externally supplied sandbox report. `zip` is the one that is
on by default, works on any file, needs nothing else, and is still
undocumented. Its entry in `default-modules` also carries no `# Still
experimental` comment, unlike `msi`, `olecf` and `vba`.
The page documents `is_zip`, the four fields of each entry, and the
fifteen values of `Compression`. That enum is `inline`, like `elf`'s
`OsAbi`, so the values are used as `zip.STORED` and not
`zip.Compression.STORED`.
### Field semantics
I took these from the module rather than from the ZIP specification,
because they are what a rule actually sees:
- `file_path` is the path as the archive stores it, so it can contain
directory separators, and it is decoded with `from_utf8_lossy`, so an
invalid sequence becomes a replacement character and the path does not
round-trip.
- `uncompressed_size` and `compressed_size` come from the entry's own
header and are not verified against the data, so comparing them is a
cheap way to spot an implausible declared ratio.
- Entries that cannot be parsed are skipped, and no more than 100000
entries are reported for a single archive.
### Verification
Both example rules were run against an archive holding a stored
`classes.dex` of 2 MiB and a deflated `res/values/strings.xml`, and both
match. A non-ZIP file does not match. The field table was checked
against the module's own output on the same archive:
```
$ yr dump --module zip sample.apk
zip:
is_zip: true
entries:
- file_path: "classes.dex"
compression: STORED
uncompressed_size: 2097160
compressed_size: 2097160
- file_path: "res/values/strings.xml"
compression: DEFLATED
uncompressed_size: 2000
compressed_size: 20
```
The weight in the front matter is 1100, which keeps the page after
`time` in the sidebar, following the rough alphabetical order of the
existing pages.
PE::parse_import_impl previously capped descriptors and per-descriptor thunks at MAX_PE_IMPORTS (16,384), while its only cumulative limit (num_imported_funcs) counted accepted functions rather than examined thunks. A crafted PE with up to 16,384 descriptors sharing or overlapping a thunk table of rejected names could force up to 16,384 * 16,384 name lookups in both ordinary and delayed imports, bypassing the scan timeout. Add a cumulative MAX_PE_IMPORT_THUNKS (65,536) budget in PE::parse_import_impl charged for every examined thunk, cap each descriptor's thunk loop and capacity estimate by the remaining budget, and stop once the budget is exhausted. Add a PE golden test fixture covering shared thunk tables for both ordinary and delayed imports. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-AKAG5DSK
verify_chain_of_matches previously had two O(N^2) paths and did not check the scan deadline: greedy chains reset chain_length across all unconfirmed matches once per confirmed head, and 3+-piece chains scanned every unconfirmed match of the preceding piece once per queued match of the current piece. In addition, a single tail atom producing many backward regexp matches could invoke verify_chain_of_matches thousands of times before returning to ac_search_loop, bypassing Scanner::set_timeout. Rewrite verify_chain_of_matches to traverse chains level-by-level backwards from the tail using SmallVec start-offset buffers (O(N + M) per level for unbounded gaps via max start offset, O((N + M) log M) for bounded gaps via sorting and binary search, and O(1) when a single start is active), hoist the greedy chain_length reset to run once after the walk finishes, move deadline into MatchTracker so verify_chain_of_matches and verify_regexp can abort promptly on timeout, and re-check the deadline at the end of ac_search_loop. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-ZPDIH45F
willdurand
marked this pull request as ready for review
December 1, 2026 08:46
willdurand
approved these changes
Dec 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR brings in the latest changes from VirusTotal/yara-x.
Commits included