Catch indefinite loop in realization due to cycle between show and grouping rule (#6259)

This commit is contained in:
Tobias Schmitz 2025-05-12 10:06:18 +02:00 committed by GitHub
parent 9b09146a6b
commit 54c5113a83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 0 deletions

View File

@ -655,6 +655,7 @@ fn visit_grouping_rules<'a>(
let matching = s.rules.iter().find(|&rule| (rule.trigger)(content, &s.kind)); let matching = s.rules.iter().find(|&rule| (rule.trigger)(content, &s.kind));
// Try to continue or finish an existing grouping. // Try to continue or finish an existing grouping.
let mut i = 0;
while let Some(active) = s.groupings.last() { while let Some(active) = s.groupings.last() {
// Start a nested group if a rule with higher priority matches. // Start a nested group if a rule with higher priority matches.
if matching.is_some_and(|rule| rule.priority > active.rule.priority) { if matching.is_some_and(|rule| rule.priority > active.rule.priority) {
@ -670,6 +671,16 @@ fn visit_grouping_rules<'a>(
} }
finish_innermost_grouping(s)?; finish_innermost_grouping(s)?;
i += 1;
if i > 512 {
// It seems like this case is only hit when there is a cycle between
// a show rule and a grouping rule. The show rule produces content
// that is matched by a grouping rule, which is then again processed
// by the show rule, and so on. The two must be at an equilibrium,
// otherwise either the "maximum show rule depth" or "maximum
// grouping depth" errors are triggered.
bail!(content.span(), "maximum grouping depth exceeded");
}
} }
// Start a new grouping. // Start a new grouping.

View File

@ -258,3 +258,11 @@ I am *strong*, I am _emphasized_, and I am #[special<special>].
= Hello = Hello
*strong* *strong*
--- issue-5690-oom-par-box ---
// Error: 3:6-5:1 maximum grouping depth exceeded
#show par: box
Hello
World