Skip to content

Commit 13d0cd4

Browse files
authored
[core] fix invalid read in Queue::write_texture (#7893)
1 parent 1da2177 commit 13d0cd4

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

wgpu-core/src/device/queue.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,6 @@ impl Queue {
860860
wgt::BufferSize::new(stage_bytes_per_row as u64 * block_rows_in_copy as u64)
861861
.unwrap();
862862
let mut staging_buffer = StagingBuffer::new(&self.device, stage_size)?;
863-
let copy_bytes_per_row = stage_bytes_per_row.min(bytes_per_row) as usize;
864863
for layer in 0..size.depth_or_array_layers {
865864
let rows_offset = layer * rows_per_image;
866865
for row in rows_offset..rows_offset + height_in_blocks {
@@ -871,7 +870,7 @@ impl Queue {
871870
data,
872871
src_offset as isize,
873872
dst_offset as isize,
874-
copy_bytes_per_row,
873+
bytes_in_last_row as usize,
875874
)
876875
}
877876
}

wgpu-core/src/resource.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,13 @@ impl StagingBuffer {
10761076
size: usize,
10771077
) {
10781078
unsafe {
1079+
debug_assert!(
1080+
(src_offset + size as isize) as usize <= data.len(),
1081+
"src_offset + size must be in-bounds: src_offset = {}, size = {}, data.len() = {}",
1082+
src_offset,
1083+
size,
1084+
data.len()
1085+
);
10791086
core::ptr::copy_nonoverlapping(
10801087
data.as_ptr().offset(src_offset),
10811088
self.ptr.as_ptr().offset(dst_offset),

0 commit comments

Comments
 (0)