Skip to content

Commit 3e0dbd8

Browse files
committed
Fix a bug in the ACP version of the file explorer
The app would crash when tryinf to read beyond the end of a file using line ranges.
1 parent f794d37 commit 3e0dbd8

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

crates/code_assistant/src/acp/explorer.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,10 @@ impl CodeExplorer for AcpCodeExplorer {
247247
}
248248
let total_lines = lines.len();
249249
let start = start_line.unwrap_or(1).saturating_sub(1);
250-
let end = end_line.unwrap_or(total_lines).saturating_sub(1);
250+
// Cap end to total_lines - 1 to prevent out-of-bounds access
251+
let end = end_line
252+
.map(|e| e.saturating_sub(1).min(total_lines - 1))
253+
.unwrap_or(total_lines - 1);
251254
if start >= total_lines || start > end {
252255
return Err(anyhow!(
253256
"Invalid line range: start={}, end={}, total_lines={}",

0 commit comments

Comments
 (0)