Skip to content

Commit cba35f6

Browse files
ShoyuVanillashashforge
authored andcommitted
Add a memory map bound check assertion on rendering const slice
1 parent 3595656 commit cba35f6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

crates/hir-ty/src/display.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,14 @@ fn render_const_scalar(
795795
let Some(bytes) = memory_map.get(addr, size_one * count) else {
796796
return f.write_str("<ref-data-not-available>");
797797
};
798+
let expected_len = count * size_one;
799+
if bytes.len() < expected_len {
800+
never!(
801+
"Memory map size is too small. Expected {expected_len}, got {}",
802+
bytes.len(),
803+
);
804+
return f.write_str("<layout-error>");
805+
}
798806
f.write_str("&[")?;
799807
let mut first = true;
800808
for i in 0..count {

0 commit comments

Comments
 (0)