Repository navigation
fix(tinyredact): keep a partial overlap's tail redacted - #310
Conversation
dedupe_overlaps dropped any hit that overlapped an earlier kept hit, so when two detectors matched overlapping ranges (0..10 and 5..15) the bytes 10..15 were left in clear text. Merge the overlapping hit into the kept one instead: the earlier, longer hit keeps its token and the combined range is redacted once.
Tiny Sweeper reviewReviewed head: Verdict: Ready for maintainer review · Priority: none Diagnostics and supporting detailsFull summaryPull request purpose (title): fix(tinyredact): keep a partial overlap's tail redacted. Tiny Sweeper completed its review; deterministic results follow. Review snapshot
Completeness: Complete What changed`dedupe_overlaps` in `crates/tinyredact/src/pii/mod.rs` no longer discards a hit whose range overlaps the previously kept hit. Instead, when the incoming hit starts before the kept hit's end, the kept hit's end is extended to the maximum of the two ends (`k.end = k.end.max(h.end)`); otherwise the hit is pushed as before. The ordering (start ascending, length descending) is unchanged, so the earlier, longer hit retains its token while the combined range is redacted once and no double redaction occurs. A doc comment now describes the merge, and a new unit test `a_partial_overlap_keeps_its_tail_redacted` in `crates/tinyredact/src/pii/mod_tests.rs` constructs hits at 5..15 (PII_PHONE) and 0..10 (PII_CC), runs `dedupe_overlaps`, and asserts the result collapses to a single (0, 15, PII_CC) range. Net change is 26 additions and 5 deletions across two files. No API changes are introduced. Features
TestsNo supported feature-to-test mapping was produced. Test execution is not inferred. FindingsNo active actionable findings. Before mergeNone. Agent review detailscritique
security
tests
commits
description
Evidence and run details
|
Summary
When two detectors matched overlapping ranges,
dedupe_overlapskept the earlier one and dropped the other entirely. For a partial overlap, for example hits at bytes 0..10 and 5..15, bytes 10..15 were left in clear text.The fix merges an overlapping hit into the kept one. The earlier, longer hit keeps its token, and the combined range is redacted once. That fails closed, and nothing is redacted twice.
Related issue
None. Found in an edge-case audit of the redaction engine.
API or behavior changes
No API change. A partial overlap is now redacted up to the end of the later hit, under the first hit's token. A fully contained overlap behaves as before.
Validation
Commands actually run, with their outcome:
cargo fmt --all -- --check. Ran rustfmt (edition 2024) on the two touched files only. CI runs the full check.cargo clippy --all-targets --all-features -- -D warnings. Left to CI; only the regression test runs locally.cargo build --all-targets --all-features. Left to CI.cargo test -p tinyredact --lib a_partial_overlap_keeps_its_tail_redacted:dedupe_overlaps: FAILED, 0 passed / 1 failed,left: [(0, 10, CREDIT_CARD)],right: [(0, 15, CREDIT_CARD)].Tests
New
a_partial_overlap_keeps_its_tail_redacted: hits (0..10) and (5..15) → one hit (0..15) carrying the first token.Documentation
The comment on
dedupe_overlapsnow describes the merge.Checklist
#[allow(...)],#[ignore], or relaxed lints.envcontents in the diff or the descriptionSummary by CodeRabbit