Subject
memchr 2.8.0, authored by Andrew Gallant (BurntSushi), implements SIMD-accelerated byte search and substring search routines for arbitrary byte slices. The public API exposes memchr/memrchr (1-, 2-, 3-needle byte search, forward and reverse), plus a memmem submodule for substring search with Finder and FinderRev types. The crate is no_std compatible, supports SSE2, AVX2 (x86_64), NEON (aarch64), and wasm-simd128, and falls back to a word-at-a-time scalar implementation on unsupported targets.
Methodology
The published crate contents were compared against the upstream Git repository at the commit recorded in .cargo_vcs_info.json using diff -rq. Source files were read in full. Tools used: diff (macOS 15.5), grep (BSD grep), and openvet 0.6.0. The 15,791 lines of Rust source across 45 files were reviewed, with particular focus on the 325 unsafe blocks concentrated in src/arch/generic/memchr.rs, src/arch/generic/packedpair.rs, src/vector.rs, src/ext.rs, and all architecture-specific facades. The unsafe_ifunc! macro and runtime CPU dispatch mechanism were read in full. Fuzz infrastructure lives in vcs/fuzz/ (excluded from the published crate as expected via exclude in Cargo.toml).
Results
The diff shows only expected differences: Cargo.toml normalization, .cargo_vcs_info.json added, Cargo.lock added (library crate with workspace lock present), and directories excluded by exclude (/.github, /benchmarks, /fuzz, /scripts) absent from the published package. No source file content divergence between contents/ and vcs/. The crate contains no binary artifacts (has-binaries), no build.rs (has-build-exec), and no install hooks (has-install-exec).
The crate is no_std and does not touch the network (uses-network), filesystem (uses-filesystem), environment variables (uses-environment), process execution (uses-exec), or cryptography (uses-crypto). It does not use or implement a JIT compiler (uses-jit, impl-jit), interpreter (uses-interpreter, impl-interpreter), parser (impl-parser), protocol (impl-protocol), or standalone data structure (impl-datastructure). Cryptographic operations are absent (impl-crypto). The crate has no integration tests outside of the src/tests inline module (has-integration-tests). The codebase was reviewed for obfuscated code, network endpoints, and suspicious payloads; none were found (is-benign). It does not implement concurrency primitives (impl-concurrency), though it does use an AtomicPtr for function-pointer caching in the x86_64 dispatch macro; this is a lock-free store of a function pointer and does not constitute a concurrency abstraction exposed to users. The crate does not spawn threads or use an async runtime, so uses-concurrency is false. The unsafe impl Send/Sync for Iter is correctly justified in a SAFETY comment at src/arch/generic/memchr.rs:1013-1022.
The dominant use of unsafe (uses-unsafe) is the SIMD search loops in src/arch/generic/memchr.rs and src/arch/generic/packedpair.rs, the platform Vector trait implementations in src/vector.rs, the pointer arithmetic utilities in src/ext.rs, and the CPU dispatch macro in src/arch/x86_64/memchr.rs. Every unsafe fn and unsafe block carries a // SAFETY: comment documenting the invariants it relies on (unsafe-documented). The unsafe surface is minimal: intrinsics and pointer arithmetic are the only use, and both are strictly necessary for SIMD (unsafe-minimal).
The runtime CPU feature detection in src/arch/x86_64/avx2/memchr.rs uses is_available(), which calls std::is_x86_feature_detected!("avx2") when std is enabled, or falls back to compile-time #[cfg(target_feature)]; the AVX2 implementation is only dispatched to after this check passes. The NEON and wasm-simd128 paths use only compile-time #[cfg(target_arch)] and #[cfg(target_feature)] gates, which is sufficient because those features are always available on their respective architectures. All pointer bounds in the aligned-load loops are guarded by debug_assert! and the loop conditions cur <= end.sub(LOOP_SIZE) ensure loads stay in bounds. The tail handling with overlapping unaligned loads is correct because the preceding load found no match (unsafe-safe).
The crate implements byte-search and substring-search algorithms (impl-algorithm), including: a classic SIMD vector search algorithm, the Two-Way string matching algorithm (O(n) search, O(m) preprocessing, O(1) space), Rabin-Karp, a Shift-Or implementation, and a "packed pair" heuristic prefilter. The algorithm-level correctness (algorithm-impl-correct) is supported by a quickcheck property test suite that cross-checks every architecture-specific implementation against a naive reference for random inputs. The VCS repository contains 8 cargo-fuzz targets covering all public-facing routines (has-fuzz-tests, has-property-tests, algorithm-impl-tested). Linear worst-case search time is guaranteed by the Two-Way fallback path (algorithm-impl-bounds). Memory safety of the algorithms follows from the unsafe-block analysis above (algorithm-impl-safe).
No findings were recorded.
Conclusion
The crate's unsafe code is concentrated at the SIMD intrinsic boundary and is uniformly documented with SAFETY comments. The CPU feature gating is correct: AVX2 code is dispatched only after a runtime or compile-time availability check. Pointer arithmetic in the search loops is bounded by loop conditions, with tail cases handled by overlapping loads rather than out-of-bounds accesses. The test infrastructure includes a quickcheck property suite applied to every architecture-specific implementation and a cargo-fuzz harness in the upstream repository. No issues were found across any class.