Skip to content

texteditor: prevent infinite syntax highlighting rule loops - #1375

Merged
visualfc merged 1 commit into
masterfrom
fix/highlighter-rule-loop
Oct 22, 2026
Merged

visualfc merged 1 commit into
masterfrom
fix/highlighter-rule-loop

Conversation

@visualfc

Copy link
Copy Markdown
Owner

Opening a file can freeze LiteIDE when syntax highlighting rules repeatedly match without consuming text. The hang report shows the main thread inside Highlighter::iterateThroughRules during rehighlighting after a file is opened.

Bound rule processing without character progress to 1024 checks per offset, and limit recursive child/fallthrough evaluation to 128 levels. On either limit, use the existing broken-highlighter fallback to stop syntax highlighting for the document while preserving its text. Clear the context stack on failure and log the block, offset, and context.

Add a standalone QtTest target covering nine scenarios: look-ahead with #stay, base-context #pop, context cycles, empty string matches, fallthrough loops, recursive children, consuming rules, and valid look-ahead transitions. Normal cases also verify formatting of a 4096-character line.

Validation:

  • Original code reproduced the base-context look-ahead #pop hang and required a test timeout after 5 seconds.
  • Qt 5.15.19 and Qt 6.11.1: all nine scenarios passed (11 QtTest results including setup/cleanup).
  • Qt 6 text editor library and liteeditor plugin builds passed.
  • git diff --check passed.

The report does not identify the exact triggering file or rule; the regression test reproduces the same class of non-progressing rule loop.

@visualfc
visualfc merged commit 9a8a9da into master Oct 22, 2026
12 checks passed
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.

1 participant