From 9407e9513c30a2a36dc9c2e9a05ea4cc58fb509c Mon Sep 17 00:00:00 2001 From: Firestar99 Date: Tue, 17 Dec 2024 17:45:28 +0100 Subject: [PATCH 1/2] ByteAddressableBuffer: fix debug printf mispile, segfaulting debug printf validation layer --- crates/spirv-std/src/byte_addressable_buffer.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/crates/spirv-std/src/byte_addressable_buffer.rs b/crates/spirv-std/src/byte_addressable_buffer.rs index 0640e54bda..6faad4434e 100644 --- a/crates/spirv-std/src/byte_addressable_buffer.rs +++ b/crates/spirv-std/src/byte_addressable_buffer.rs @@ -70,14 +70,12 @@ fn bounds_check(data: &[u32], byte_index: u32) { if byte_index % 4 != 0 { panic!("`byte_index` should be a multiple of 4"); } - if byte_index + sizeof > data.len() as u32 { - let last_byte = byte_index + sizeof; + let last_byte = byte_index + sizeof; + let len = data.len() as u32; + if byte_index + sizeof > len { panic!( "index out of bounds: the len is {} but loading {} bytes at `byte_index` {} reads until {} (exclusive)", - data.len(), - sizeof, - byte_index, - last_byte, + len, sizeof, byte_index, last_byte, ); } } From 01373cd84f708aaf4cc7704ffd3564a3bc9365ae Mon Sep 17 00:00:00 2001 From: Firestar99 Date: Tue, 17 Dec 2024 17:45:49 +0100 Subject: [PATCH 2/2] ByteAddressableBuffer: fix oob calculation thinking all buffers are only `len / 4` long --- crates/spirv-std/src/byte_addressable_buffer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/spirv-std/src/byte_addressable_buffer.rs b/crates/spirv-std/src/byte_addressable_buffer.rs index 6faad4434e..f4c6dba491 100644 --- a/crates/spirv-std/src/byte_addressable_buffer.rs +++ b/crates/spirv-std/src/byte_addressable_buffer.rs @@ -71,7 +71,7 @@ fn bounds_check(data: &[u32], byte_index: u32) { panic!("`byte_index` should be a multiple of 4"); } let last_byte = byte_index + sizeof; - let len = data.len() as u32; + let len = data.len() as u32 * 4; if byte_index + sizeof > len { panic!( "index out of bounds: the len is {} but loading {} bytes at `byte_index` {} reads until {} (exclusive)",