From 6c785a671539d37fddc151042a1be07fffc47997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20F=C3=B6rster?= Date: Sun, 3 Dec 2023 14:11:22 +0100 Subject: [PATCH] Fix potential crash when parsing build logs (#973) When encountering an error in the build log file, the server tries to convert the line number into a (zero)-based offset. If the line number is (for some reason) completely wrong, a panic in the server can occur. --- CHANGELOG.md | 1 + crates/line-index/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0246d79..9509f63c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Do not report `undefined reference` errors when using `\nocite{*}` ([#964](https://github.com/latex-lsp/texlab/issues/964)) +- Fix potential crash when parsing build log files ([#973](https://github.com/latex-lsp/texlab/issues/973)) ## [5.11.0] - 2023-11-05 diff --git a/crates/line-index/src/lib.rs b/crates/line-index/src/lib.rs index 20161d49..f604825d 100644 --- a/crates/line-index/src/lib.rs +++ b/crates/line-index/src/lib.rs @@ -114,7 +114,7 @@ impl LineIndex { } pub fn offset(&self, line_col: LineCol) -> Option { - Some(self.newlines[line_col.line as usize] + TextSize::from(line_col.col)) + Some(self.newlines.get(line_col.line as usize)? + TextSize::from(line_col.col)) } pub fn to_utf16(&self, line_col: LineCol) -> Option {