Skip to content

chore: sync upstream changes (2dde7d79) - #190

Merged
willdurand merged 5 commits into
amofrom
sync/upstream-2dde7d79
Dec 3, 2026
Merged

willdurand merged 5 commits into
amofrom
sync/upstream-2dde7d79

Conversation

@github-actions

@github-actions github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

This PR brings in the latest changes from VirusTotal/yara-x.

Commits included

2dde7d79 test(scanner): assert the undefined guarantees of block scanning mode (#928)
625c2694 fix(wasm): share Rc<BString> keys when iterating string-keyed maps
1b16314e docs(cli): document missing options and the completion command (#918)
bc2431ac fix(elf): locate PT_DYNAMIC via loader-order PT_LOAD map

Generated automatically by the Sync Upstream workflow.

plusvic and others added 5 commits December 2, 2026 10:54
ElfParser::parse_dyn_entries previously read p_offset..p_offset + p_filesz as an all-or-nothing slice, dropping all dynamic entries when PT_DYNAMIC had p_filesz extending past EOF, overflowing, zeroed, truncated, or a mismatched p_offset. Because the dynamic linker reads the table from memory at p_vaddr up to DT_NULL, an ELF could empty elf.dynamic while running normally.

Add a lazily constructed BTreeMap-based LoadMap over file-backed PT_LOAD segments applied in program-header order (amortized O(L log L) build, O(log L) lookup) so later mappings override earlier overlapping decoys, modeling 4 KiB page rounding and .bss tail clearing. When no PT_LOAD maps p_vaddr (such as stripped debuginfo files), fall back to Phdr::offset_range() clamped at EOF. Update 0a0a8ae4...out (recovering 19 real DT_* entries) and add an ELF64 golden fixture covering these cases.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-FZU9PASY
I compared the CLI reference against `yr --help` for every subcommand on
`main` (`46bd8570`, built locally as 1.25.0). Five things that the
binary reports are not on the page:

| | added in | |
|---|---|---|
| `scan --fast-scan`, `-f` | `297ceb97` | 2026-05-27 |
| `scan --ignore-invalid-rules` | `6e6ad7a9` (#704) | 2026-07-14 |
| `compile --ignore-invalid-rules` | `6e6ad7a9` (#704) | 2026-07-14 |
| `compile --define` | documented for `scan`, not for `compile` | |
| the `completion` command | `9d564792` | 2024-04-04 |

Everything else lines up: `dump`, `fmt`, `fix` and `deps` have every
option documented, and nothing on the page is absent from the binary.

The wording is taken from each command's own help text. The two options
that `compile` shares with `scan` use the existing "See ... for the scan
command" form, and the new sections are inserted where the page's
current ordering puts them. `--help` was the only source, so no
behaviour is being described that the CLI does not already state.

One detail I checked rather than assumed: the link for `compile
--define` points at `#--define-varvalue`, which is the anchor the
published page actually generates for `### --define <VAR=VALUE>`.
Repeated headings get a `-1` suffix there, which is how the existing
`compile` entries for `--include-dir` and `--ignore-module` already
behave.

No code changes.
Iterating a Map::StringKeys from WASM previously allocated a fresh Rc<BString> copy of each key on every lookup, causing ScanContext::runtime_objects to retain duplicate copies for the duration of the scan and enabling unbounded memory growth on repeated loops over long attacker-controlled keys (such as pe.version_info).

Wrap Map::StringKeys keys in a StringKey(Rc<BString>) newtype implementing Borrow<BStr> so &BStr lookups and serde serialization stay unchanged, and clone the existing Rc handle in map_lookup_by_index_* instead of copying the key bytes. Add a regression test asserting runtime_objects stays bounded across 1,000 iterations of string-keyed maps.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-6QH2G84S
… (#928)

Block scanning mode documents four things as undefined. Two of them had
no
assertion behind them, so this adds one for each, and corrects two
statements
in the same list that turned out not to match what the code does.

I went looking for a bug here rather than for test gaps. A differential
harness
compared `blocks::Scanner` against `Scanner` over roughly 11,700
generated
cases: random patterns with random block cuts, inputs built so that one
block
holds many matches whose context ranges overlap, blocks delivered with
gaps and
out of order, overlapping blocks with consistent data, and the `at`,
`in` and
`#a` conditions. The expectation was derived from the documented model,
that
each block is its own universe, by scanning each block alone with the
normal
scanner and shifting the offsets, rather than from a rule of my own
invention.
`Match::data()` was checked against the real bytes at `Match::range()`,
and
`data_with_context()` against the data at the offset its relative range
implies.

Nothing diverged, and nothing panicked. The snippet merging added in
`5f19c5a7`
holds up, including the nested case it was written for: with twenty `MZ`
copies
before one `PE` and a context size of 8, one block holds twenty matches
whose
expanded ranges overlap nineteen times, they collapse to a single
snippet keyed
at 0, and every lookup resolves correctly.

What the run did turn up is below. None of it is a bug.

## Limitation 3 had no test

`uint8` and friends are documented as returning `undefined` in block
scanning
mode. The only occurrences of `uint8` in the test module are inside
`block_scanner_timeout` and `block_scanner_reuse_after_timeout`, where
the
function is there to burn CPU, so nothing asserted the guarantee.

`block_scanner_integer_functions` adds it for `uint8`, `uint32be`,
`defined`
and a negated comparison, the last one because undefinedness propagates
and it
would be easy to regress only that case.

## Limitation 4 was asserted on an empty stream

`block_scanner_filesize` compiles `not defined filesize` and then calls
`finish()` without scanning any blocks, so it never exercised the
guarantee
during an actual block scan. Two blocks are now scanned before the same
assertion.

Both tests pair the block scanner with the normal scanner on the same
rules.
The normal scanner reaches a verdict on every condition, which is what
makes
the block scanner's silence meaningful instead of passing because the
conditions never decided anything.

## Two corrections to the limitations list

Limitation 1 says modules won't work. Module functions that do not look
at the
scanned data still do: `string.length("abc")` and `time.now()` reach the
same
verdict under both scanners. What is undefined is anything that needs
the
scanned data, and the PE and ELF fields are genuinely undefined rather
than
defaulted, which is the safe behaviour. `not pe.is_pe` does not fire in
block
scanning mode.

Limitation 2 says the hash functions return `undefined` "when used in a
multi-block context". They return `undefined` in block scanning mode
even when
all the data arrives in a single block. That is also what
`block_scanner_memoized_module_functions` already relies on, since it
scans one
block and expects no match.

## Checks

`cargo test -p yara-x --lib scanner::blocks` passes, 17 tests. The
module's
doctests pass. `cargo fmt --check` is clean. No production code is
touched.
@willdurand
willdurand marked this pull request as ready for review December 3, 2026 09:49
@willdurand
willdurand merged commit 6e1b958 into amo Dec 3, 2026
6 checks passed
@willdurand
willdurand deleted the sync/upstream-2dde7d79 branch December 3, 2026 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants