Harden glob compilation + property/fuzz tests; edition 2024, MSRV 1.85, release 0.2.0 - #1
Merged
Merged
Conversation
…RV 1.85
- Cap brace expansion at MAX_BRACE_ALTS so a short "{a,b}"×N brace bomb can
no longer OOM Pattern::compile; a pattern past the cap degrades to a single
literal alternative (same leniency as an unmatched brace).
- Add proptest properties for the parser (totality, non-empty action/name on
Ok) and the glob engine (compile is total and bounded, literals are
full-anchored, brace strings stay within the cap).
- Add a standalone cargo-fuzz crate with parse + glob targets; the glob target
asserts the brace cap as a fuzz invariant. Exclude /fuzz from the published
crate.
- Bump to edition 2024 and raise MSRV to 1.85 (edition floor, also >= pyo3 0.28
which needs 1.83); add a CI job that builds + tests on 1.85.
Bump the crate version 0.1.0 -> 0.2.0 and the README install references.
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.
Harden glob compilation + property/fuzz tests; edition 2024, MSRV 1.85, release 0.2.0
TL;DR
Closes a compile-time DoS in the glob engine (a short brace "bomb" could OOM
Pattern::compile), backs the engine's safety claims withproptest+cargo-fuzz, modernizes the toolchain to edition 2024 / MSRV 1.85, and cuts v0.2.0.Why
The README promised "linear-time, no catastrophic backtracking on untrusted patterns" — but that only covered matching. Brace compilation was the gap:
{a,b}{c,d}…is a cross product, so a short adversarial pattern ({a,b}×30 — a few bytes) demanded 2³⁰ sub-patterns and blew up memory at compile time, before the linear matcher ever ran.directiva::source::fileparses untrusted directive files, so this was reachable.Separately, the declared
rust-version = "1.74"was fiction: pyo3 0.28 (thepythonfeature) already needs 1.83, and nothing verified the floor.What changed
The fix — bounded compilation. Brace expansion now caps the running cross product at a public
MAX_BRACE_ALTS(core::glob, = 1024). A pattern that would exceed it degrades to a single literal alternative (braces matched verbatim — the same leniency already applied to an unmatched brace). The check happens before allocation, so both time and memory stayO(cap · depth)on any input — neverO(2ⁿ).Property tests (
proptest, a dev-dependency). Run as part ofcargo test:Result, never panics) and anyOkhas a non-empty action + NAME;compileis total and bounded (alt_count ∈ [1, MAX_BRACE_ALTS]),matchesnever panics, metachar-free patterns are full-anchored.Fuzzing (
cargo-fuzz). A standalonefuzz/crate (own workspace, nightly-only) withparseandglobtargets; the glob target asserts the brace cap as a fuzz invariant. Excluded from the published crate. Both targets ran clean locally (~478k / ~611k execs, 0 crashes, ASan).Toolchain. Edition 2021 → 2024; MSRV 1.74 → 1.85 (edition floor, ≥ pyo3's 1.83), now pinned by a dedicated CI job (
cargo test+cargo check --features pythonon 1.85).Release. Version 0.1.0 → 0.2.0 + README install references.
Testing
cargo test— 64 tests pass (was 56: +brace-cap units, +5 proptest properties).cargo clippy --all-targets -- -D warningsandcargo clippy --features python -- -D warnings— clean.cargo fmt --check— clean.cargo testgreen,cargo check --features pythongreen.cargo +nightly fuzz run parse|glob— clean.Notes
nightlyis required only to run the fuzzers (cargo-fuzz needs-Zsanitizer*); the library, tests, proptest, and clippy are all stable.MAX_BRACE_ALTSis the one new public item.