ICU 72 - prevent stack overflow in collator #691
Merged
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.
Problem this PR is fixing
See: dotnet/runtime#121202 (comment).
Recursive canonical-closure expansion in ICU’s canonical iterator and collation importer could revisit the same substring/import chain indefinitely. With deeply nested or cyclic decompositions/imports, the iterator would overflow the stack and [import …] would spin forever (or until the host stack failed).
Fixes
caniter.cpp: added a cycle guard. Every segment encountered during the recursive walk is tracked in a “visited” setcollectEquivalentsRecursiveso we stop recursing once we see the same canonical form again. Prevents runaway recursion and keeps closure generation finite.collationruleparser.cppintroducedimportRecursionGuard, a hash table that records the [import locale/type] pairs currently being processed. If an import re-enters one of those pairs, we break out instead of chasing the loop, stopping the stack overflow. Normalized the locale/type strings before storing them, and updated the cleanup so the guard is cleared as we unwind.Together these changes keep both canonical closure expansion and rule imports from recursing indefinitely while touching only the minimal code paths needed for the stack overflow fix.
Filters were restored to the state from before #686 and prebuilts were updated accordingly.