Repository navigation
fnmatch: replace recursive matcher with iterative greedy algorithm - #22911
Closed
MegaManSec wants to merge 1 commit into
Closed
MegaManSec wants to merge 1 commit into
MegaManSec wants to merge 1 commit into
Conversation
The fallback matcher did recursive backtracking and could do O(pattern length * string length^2) work for a non-match. Use iterative greedy matching that backtracks only to the most recent '*', reducing the bound to O(pattern length * string length). Preserve the existing wildcard syntax and two-star-group limit.
MegaManSec
force-pushed
the
worktree-agent-a9e3ffe051cb25e36
branch
from
September 11, 2026 06:54
24e04b3 to
e179a2a
Compare
There was a problem hiding this comment.
🟢 Approval recommended
The implementation preserves tested behavior while removing recursive quadratic backtracking.
Pull request overview
Replaces recursive FTP wildcard matching with bounded iterative backtracking while preserving existing semantics.
Changes:
- Adds token-level matching and iterative
*handling. - Tests the two-star-group limit across implementations.
File summaries
| File | Description |
|---|---|
lib/curl_fnmatch.c |
Implements the iterative matcher. |
tests/unit/unit1307.c |
Adds star-group-limit coverage. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The fallback FTP wildcard matcher recursively tried pattern suffixes at every possible string position. A non-matching pattern such as 'ab' against a long string could therefore take O(pattern length * string length²) work.
Replace the recursion with an iterative greedy matcher that backtracks only to the most recent '*', reducing the bound to O(pattern length * string length). Character classes, escapes, '?', and the existing two-star-group limit retain their behavior.
Unit test 1307 covers the preserved star-group limit.