mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-21 22:33:49 +00:00
add missing indirect buffer offset validation
This commit is contained in:
parent
0903ba6d47
commit
7ac533a312
@ -136,6 +136,8 @@ pub enum ComputePassErrorInner {
|
||||
BindGroupIndexOutOfRange { index: u32, max: u32 },
|
||||
#[error(transparent)]
|
||||
DestroyedResource(#[from] DestroyedResourceError),
|
||||
#[error("Indirect buffer offset {0:?} is not a multiple of 4")]
|
||||
UnalignedIndirectBufferOffset(BufferAddress),
|
||||
#[error("Indirect buffer uses bytes {offset}..{end_offset} which overruns indirect buffer of size {buffer_size}")]
|
||||
IndirectBufferOverrun {
|
||||
offset: u64,
|
||||
@ -845,6 +847,10 @@ fn dispatch_indirect(
|
||||
.merge_single(&buffer, hal::BufferUses::INDIRECT)?;
|
||||
buffer.check_usage(wgt::BufferUsages::INDIRECT)?;
|
||||
|
||||
if offset % 4 != 0 {
|
||||
return Err(ComputePassErrorInner::UnalignedIndirectBufferOffset(offset));
|
||||
}
|
||||
|
||||
let end_offset = offset + size_of::<wgt::DispatchIndirectArgs>() as u64;
|
||||
if end_offset > buffer.size {
|
||||
return Err(ComputePassErrorInner::IndirectBufferOverrun {
|
||||
|
@ -638,6 +638,8 @@ pub enum RenderPassErrorInner {
|
||||
MissingFeatures(#[from] MissingFeatures),
|
||||
#[error(transparent)]
|
||||
MissingDownlevelFlags(#[from] MissingDownlevelFlags),
|
||||
#[error("Indirect buffer offset {0:?} is not a multiple of 4")]
|
||||
UnalignedIndirectBufferOffset(BufferAddress),
|
||||
#[error("Indirect draw uses bytes {offset}..{end_offset} {} which overruns indirect buffer of size {buffer_size}",
|
||||
count.map_or_else(String::new, |v| format!("(using count {v})")))]
|
||||
IndirectBufferOverrun {
|
||||
@ -2450,6 +2452,10 @@ fn multi_draw_indirect(
|
||||
|
||||
let actual_count = count.map_or(1, |c| c.get());
|
||||
|
||||
if offset % 4 != 0 {
|
||||
return Err(RenderPassErrorInner::UnalignedIndirectBufferOffset(offset));
|
||||
}
|
||||
|
||||
let end_offset = offset + stride as u64 * actual_count as u64;
|
||||
if end_offset > indirect_buffer.size {
|
||||
return Err(RenderPassErrorInner::IndirectBufferOverrun {
|
||||
@ -2534,6 +2540,10 @@ fn multi_draw_indirect_count(
|
||||
count_buffer.check_usage(BufferUsages::INDIRECT)?;
|
||||
let count_raw = count_buffer.try_raw(state.snatch_guard)?;
|
||||
|
||||
if offset % 4 != 0 {
|
||||
return Err(RenderPassErrorInner::UnalignedIndirectBufferOffset(offset));
|
||||
}
|
||||
|
||||
let end_offset = offset + stride * max_count as u64;
|
||||
if end_offset > indirect_buffer.size {
|
||||
return Err(RenderPassErrorInner::IndirectBufferOverrun {
|
||||
|
Loading…
Reference in New Issue
Block a user