Skip to content

ignore: fix panic recovery after filter_entry panic#3344

Open
lopopolo wants to merge 2 commits intoBurntSushi:masterfrom
lopopolo:codex/ignore-walk-panic-safety
Open

ignore: fix panic recovery after filter_entry panic#3344
lopopolo wants to merge 2 commits intoBurntSushi:masterfrom
lopopolo:codex/ignore-walk-panic-safety

Conversation

@lopopolo
Copy link
Copy Markdown

@lopopolo lopopolo commented Apr 2, 2026

Summary

This fixes panic recovery in ignore::Walk after a panicking filter_entry predicate.

Before this change, Walk::next called filter_entry on a directory before it pushed the child ignore matcher. If the predicate panicked and the caller resumed iteration with catch_unwind, the later WalkEvent::Exit still popped an ignore frame. That could drop ignore rules for later siblings and leak paths that .ignore should have hidden. The new regression test demonstrates the failure by leaking x and x/file.

The fix moves the child ignore-state transition ahead of the user callback so the ignore stack stays balanced across a recovered panic.

Context

I found this bug with OpenAI Codex while auditing ripgrep for bugs in the same unwind-safety class as RUSTSEC-2026-0078. @lopopolo reviewed and validated the reproducer, patch, and PR.

Validation

  • cargo test -p ignore filter_entry_panic_should_not_drop_ignore_rules_for_later_siblings -- --nocapture
  • cargo test -p ignore --lib
  • cargo fmt --all --check

@lopopolo lopopolo changed the title [codex] ignore: preserve Walk state across filter panics [codex] ignore: fix Walk ignore-stack corruption after filter panic Apr 2, 2026
@lopopolo lopopolo changed the title [codex] ignore: fix Walk ignore-stack corruption after filter panic ignore: fix panic recovery after filter_entry panic Apr 2, 2026
@lopopolo lopopolo marked this pull request as ready for review April 2, 2026 07:14
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.

1 participant