From b1cc82bb5146fc9fecae49258ffd69eaa9beb1d6 Mon Sep 17 00:00:00 2001 From: Benoit de Chezelles Date: Tue, 16 Jun 2026 09:42:32 +0200 Subject: [PATCH] fix: prevent infinite loop when pane search regex fails (#7864) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `fancy_regex` returns Err (e.g. backtracking limit exceeded) without advancing the iterator position, causing `captures_iter` to loop forever on the same offset. 😬 👉 Break out and warn instead. fixes: #7773 --- mux/src/localpane.rs | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/mux/src/localpane.rs b/mux/src/localpane.rs index dac7e394d..0c85661c3 100644 --- a/mux/src/localpane.rs +++ b/mux/src/localpane.rs @@ -721,24 +721,34 @@ impl Pane for LocalPane { CompiledPattern::Regex(re) => { // Allow for the regex to contain captures for capture_res in re.captures_iter(&haystack) { - if let Ok(c) = capture_res { - // Look for the captures in reverse order, as index==0 is - // the whole matched string. We can't just call - // `c.iter().rev()` as the capture iterator isn't double-ended. - for idx in (0..c.len()).rev() { - if let Some(m) = c.get(idx) { - found_match( - m.as_str(), - m.start(), - lines, - stable_idx, - &mut uniq_matches, - &mut coords, - &mut results, - ); - break; + match capture_res { + Ok(c) => { + // Look for the captures in reverse order, as index==0 is + // the whole matched string. We can't just call + // `c.iter().rev()` as the capture iterator isn't double-ended. + for idx in (0..c.len()).rev() { + if let Some(m) = c.get(idx) { + found_match( + m.as_str(), + m.start(), + lines, + stable_idx, + &mut uniq_matches, + &mut coords, + &mut results, + ); + break; + } } } + Err(err) => { + // On errors like max backtracking limit reached, fancy_regex does + // NOT advance the iterator position, so silently ignoring Err + // would loop forever. + log::warn!("line {stable_idx} search error: {err}"); + log::warn!("stopping collecting matches on line {stable_idx}"); + break; + } } } } -- 2.51.2