From dffa37ca8f95aa4a22b1e540a36098104ec214d9 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Fri, 5 Apr 2024 11:50:52 -0300 Subject: [PATCH] fix: out-of-bounds panic when diffing a large number of words Fixes #688, fixes #694 and fixes #682. --- src/line_parser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/line_parser.rs b/src/line_parser.rs index d54731d598..562d327d12 100644 --- a/src/line_parser.rs +++ b/src/line_parser.rs @@ -152,7 +152,7 @@ pub(crate) fn change_positions(lhs_src: &str, rhs_src: &str) -> Vec // have a very large number of words, don't diff // individual words. if lhs_words.len() > MAX_WORDS_IN_LINE || rhs_words.len() > MAX_WORDS_IN_LINE { - for lhs_pos in lhs_lp.from_region(lhs_offset, lhs_offset + lhs_part.len()) { + for lhs_pos in lhs_lp.from_region(lhs_offset, lhs_offset + line_len_in_bytes(&lhs_part)) { mps.push(MatchedPos { kind: MatchKind::NovelWord { highlight: TokenKind::Atom(AtomKind::Normal),