Address out-of-bounds panic in inline completion button (#26394)

Closes #26350

Release Notes:

- Git Beta: Fixed a panic that could occur when using the project diff
This commit is contained in:
Cole Miller 2025-03-11 03:04:56 -04:00 committed by GitHub
parent 9bd3e156f5
commit 0df1e4a489
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 2 deletions

View file

@ -4175,6 +4175,9 @@ impl MultiBufferSnapshot {
let region = cursor.region()?;
let overshoot = offset - region.range.start;
let buffer_offset = region.buffer_range.start + overshoot;
if buffer_offset > region.buffer.len() {
return None;
}
Some((region.buffer, buffer_offset))
}
@ -4183,8 +4186,11 @@ impl MultiBufferSnapshot {
cursor.seek(&point);
let region = cursor.region()?;
let overshoot = point - region.range.start;
let buffer_offset = region.buffer_range.start + overshoot;
Some((region.buffer, buffer_offset, region.is_main_buffer))
let buffer_point = region.buffer_range.start + overshoot;
if buffer_point > region.buffer.max_point() {
return None;
}
Some((region.buffer, buffer_point, region.is_main_buffer))
}
pub fn suggested_indents(

View file

@ -3378,6 +3378,17 @@ fn assert_position_translation(snapshot: &MultiBufferSnapshot) {
}
}
}
let point = snapshot.max_point();
let Some((buffer, offset)) = snapshot.point_to_buffer_offset(point) else {
return;
};
assert!(offset <= buffer.len(),);
let Some((buffer, point, _)) = snapshot.point_to_buffer_point(point) else {
return;
};
assert!(point <= buffer.max_point(),);
}
fn assert_line_indents(snapshot: &MultiBufferSnapshot) {