diff options
| author | Shoyu Vanilla <modulo641@gmail.com> | 2025-07-11 23:44:49 +0900 |
|---|---|---|
| committer | Shoyu Vanilla <modulo641@gmail.com> | 2025-07-11 23:44:49 +0900 |
| commit | f15dfa85cc77df29b40c6b68328780c9075e09c2 (patch) | |
| tree | 08bb20840dc174df57618b30b91906bf32683619 | |
| parent | 5a9030840db3399c664035617cb0e3db7f132f8a (diff) | |
| download | rust-f15dfa85cc77df29b40c6b68328780c9075e09c2.tar.gz rust-f15dfa85cc77df29b40c6b68328780c9075e09c2.zip | |
Add a memory map bound check assertion on rendering const slice
| -rw-r--r-- | src/tools/rust-analyzer/crates/hir-ty/src/display.rs | 8 |
1 files changed, 8 insertions, 0 deletions
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 61d62650453..b3760e3a382 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("<ref-data-not-available>"); }; + 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("<layout-error>"); + } f.write_str("&[")?; let mut first = true; for i in 0..count { |
