Skip to content

Conversation

Copy link

Copilot AI commented Nov 5, 2025

The match function in TxtaiStore._matches_filters recursively processes nested collections but lacked depth protection, risking stack overflow with deeply nested or circular structures.

Changes:

  • Added depth parameter to match function with _FILTER_MATCH_MAX_DEPTH = 10 class constant
  • Returns False with warning log when depth limit exceeded
  • Recursive collection traversal now increments depth counter
def match(have: Any, cond: Any, depth: int = 0) -> bool:
    if depth >= TxtaiStore._FILTER_MATCH_MAX_DEPTH:
        log.warning(f"Filter match depth limit ({TxtaiStore._FILTER_MATCH_MAX_DEPTH}) exceeded")
        return False
    
    if isinstance(have, (list, tuple, set)):
        return any(match(item, cond, depth + 1) for item in have)
    # ... rest of matching logic

Normal filter operations unaffected; only prevents pathological cases beyond 10 nesting levels.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Base automatically changed from codex/fix-sql-query-escaping-and-add-tests to main November 5, 2025 01:08
Copilot AI and others added 2 commits November 5, 2025 01:13
Co-authored-by: rodrigopitanga <1755608+rodrigopitanga@users.noreply.github.com>
Co-authored-by: rodrigopitanga <1755608+rodrigopitanga@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP address feedback on 'Sanitize txtai metadata persistence' PR Prevent infinite recursion in filter match with depth limit Nov 5, 2025
Copilot AI requested a review from rodrigopitanga November 5, 2025 01:19
@rodrigopitanga rodrigopitanga force-pushed the main branch 2 times, most recently from 0288107 to 8e8a634 Compare November 5, 2025 14:38
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.

2 participants