From 954bee635ee863a8ecbe8fdbd221f02923589310 Mon Sep 17 00:00:00 2001 From: paxcut <53811119+paxcut@users.noreply.github.com> Date: Fri, 2 Jan 2026 08:04:35 -0700 Subject: [PATCH] fix: Text highlighter crash (#2595) The assumption that the number of lines of colors will be equal to the number of lines in the input signal is incorrect. As issue #2594 shows, erroneous input can cause the lexer to end processing the input file prematurely thus being unable to create tokens past the line where the error occurred which in turn implies that no colors can be found beyond those lines. To fix the crash (the underlying problem is user caused and can't be fixed) is to use the size of the vectors containing the first token index of each line since that size must be equal to the number of lines stored in token sequence. Fixes #2594 (cherry picked from commit 5756105347539b1021d6b1d04df3a88fe5003b0d) --- .../source/content/text_highlighting/pattern_language.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/builtin/source/content/text_highlighting/pattern_language.cpp b/plugins/builtin/source/content/text_highlighting/pattern_language.cpp index 7b0737f45..c43e5f6ab 100644 --- a/plugins/builtin/source/content/text_highlighting/pattern_language.cpp +++ b/plugins/builtin/source/content/text_highlighting/pattern_language.cpp @@ -1575,7 +1575,9 @@ namespace hex::plugin::builtin { void TextHighlighter::setRequestedIdentifierColors() { auto topLine = 0; - auto bottomLine = m_lines.size(); + while (m_firstTokenIdOfLine.at(topLine) == -1) + topLine++; + auto bottomLine = previousLine(m_firstTokenIdOfLine.size()); for (u32 line = topLine; line < bottomLine; line = nextLine(line)) { if (m_lines[line].empty()) continue;