Repository navigation
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the changes addressing input validation, offset safety, and BMI2 portability.
No open issues 🎉
What changed in this PR
This PR follows up on #175 by addressing six remaining medium- and low-severity code-scanning alerts across four crates.
Changes:
- Reject empty regex matches, invalid mask sizes, and reservoir sizes that exceed the population.
- Use saturating offset arithmetic and validate content length before narrowing offsets to
u32. - Gate the BMI2 intrinsic on compile-time feature support and add regression tests for invalid inputs and maximum offsets.
| File | Description |
|---|---|
crates/string-offsets/src/lib.rs |
Prevents offset overflow, validates content length, and tests maximum offsets. |
crates/geo_filters/src/diff_count.rs |
Tests rejection of a zero mask size. |
crates/geo_filters/src/config/bitchunks.rs |
Validates mask size before constructing the iterator. |
crates/geo_filters/src/config.rs |
Uses the portable fallback when BMI2 is not enabled. |
crates/consistent-choose-k/src/consistent_reservoir.rs |
Enforces k <= n and tests rejection of invalid sizes. |
crates/bpe-openai/src/lib.rs |
Rejects empty matches regardless of lookahead mode and adds a regression test. |
Review effort: Balanced (auto)
aneubeck
marked this pull request as draft
November 4, 2026 15:14
This branch has not been deployed
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.
Summary
Fixes the remaining 3 Medium-severity and 3 Low-severity
ai-scan/*code-scanning alerts acrossbpe-openai,consistent-choose-k,geo_filters, andstring-offsets(tracked ingithub/blackbird#17346, following up on #175):Medium-severity alerts
bpe-openaiai-scan/cwe-835,crates/bpe-openai/src/lib.rs:204): Move the non-empty match assertionassert_ne!(end, start, ...)outside theself.lookaheadbranch inSplits::nextso any caller-supplied regex that matches an empty string panics immediately instead of looping infinitely.geo_filtersai-scan/cwe-835,crates/geo_filters/src/config/bitchunks.rs:182): Assert(1..BITS_PER_BLOCK).contains(&modulus)inMaskedBitChunksIterator::new(matchingGeoDiffCount::masked_sort_key) socmp_maskedwithmask_size == 0panics instead of looping infinitely oni *= 2.consistent-choose-kai-scan/cwe-400,crates/consistent-choose-k/src/consistent_reservoir.rs:286): Enforce the documentedassert!(k <= n, "k must be at most n")invariant inConsistentReservoir::newto prevent exhausting the full permutation layer (up tok > n.Low-severity alerts
string-offsetsai-scan/cwe-190,crates/string-offsets/src/lib.rs:291): Usesaturating_add(1)/saturating_sub(1)inStringOffsets::utf8_to_charandline_to_utf8_endsousize::MAXoffsets saturate to the end of the string as documented instead of overflowing.ai-scan/cwe-197,crates/string-offsets/src/lib.rs:395): Assertu32::try_from(content.len()).is_ok()innew_converterbefore casting line start offsets tou32.geo_filtersai-scan/cwe-758,crates/geo_filters/src/config.rs:339): Gate the_pdep_u64implementation ofnth_oneon#[cfg(all(target_arch = "x86_64", target_feature = "bmi2"))], falling back to the portable bit-clearing loop when compiled withoutbmi2.Test plan
cargo fmt --all -- --checkcargo clippy -- --no-deps --deny warnings -D clippy::unwrap_usedcargo clippy --tests -- --no-deps --deny warnings -A clippy::unwrap_usedcargo test -p consistent-choose-k -p geo_filters -p bpe-openai -p string-offsets