From a38c2a19a125067515ac2e47d0d751bff7672ef0 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Wed, 29 Nov 2023 18:00:43 +0000 Subject: [PATCH] Uniscribe: Add defensive checks to UniscribeParagraphLayout::NextLine --- src/os/windows/string_uniscribe.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/os/windows/string_uniscribe.cpp b/src/os/windows/string_uniscribe.cpp index bd17e6677c..4318be6b86 100644 --- a/src/os/windows/string_uniscribe.cpp +++ b/src/os/windows/string_uniscribe.cpp @@ -376,7 +376,7 @@ static std::vector UniscribeItemizeString(UniscribeParagraphLayoutF /* Walk backwards to find the last suitable breaking point. */ while (--num_chars > this->cur_range_offset && !log_attribs[num_chars].fSoftBreak && !log_attribs[num_chars].fWhiteSpace) {} - if (num_chars == this->cur_range_offset) { + if (num_chars <= this->cur_range_offset) { /* Didn't find any suitable word break point, just break on the last cluster boundary. */ num_chars = last_cluster; } @@ -384,7 +384,9 @@ static std::vector UniscribeItemizeString(UniscribeParagraphLayoutF /* Eat any whitespace characters before the breaking point. */ while (num_chars - 1 > this->cur_range_offset && log_attribs[num_chars - 1].fWhiteSpace) num_chars--; /* Count whitespace after the breaking point. */ - while (num_chars + whitespace_count < (int)log_attribs.size() && log_attribs[num_chars + whitespace_count].fWhiteSpace) whitespace_count++; + while (num_chars + whitespace_count >= 0 && num_chars + whitespace_count < (int)log_attribs.size() && log_attribs[num_chars + whitespace_count].fWhiteSpace) { + whitespace_count++; + } /* Get last run that corresponds to the number of characters to show. */ for (std::vector::iterator run = start_run; run != last_run; run++) {