From f15dfa85cc77df29b40c6b68328780c9075e09c2 Mon Sep 17 00:00:00 2001 From: Shoyu Vanilla Date: Fri, 11 Jul 2025 23:44:49 +0900 Subject: [PATCH] Add a memory map bound check assertion on rendering const slice --- src/tools/rust-analyzer/crates/hir-ty/src/display.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/display.rs b/src/tools/rust-analyzer/crates/hir-ty/src/display.rs index 61d626504537..b3760e3a3822 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/display.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/display.rs @@ -795,6 +795,14 @@ fn render_const_scalar( let Some(bytes) = memory_map.get(addr, size_one * count) else { return f.write_str(""); }; + let expected_len = count * size_one; + if bytes.len() < expected_len { + never!( + "Memory map size is too small. Expected {expected_len}, got {}", + bytes.len(), + ); + return f.write_str(""); + } f.write_str("&[")?; let mut first = true; for i in 0..count {