From f76b631961b6b82e77e79c6b3f522bef49794cdb Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Tue, 7 Jul 2020 14:35:03 -0400 Subject: [PATCH] Validate set_bind_group is within bounds of limit --- wgpu-core/src/command/bundle.rs | 7 +++++++ wgpu-core/src/command/compute.rs | 7 +++++++ wgpu-core/src/command/render.rs | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index cfb7cc4a20..e5aa06391f 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -528,6 +528,13 @@ impl Global { num_dynamic_offsets, bind_group_id, } => { + assert!( + (index as u32) < device.limits.max_bind_groups, + "Bind group index {0} is out of range 0..{1} provided by requested max_bind_group limit {1}", + index, + device.limits.max_bind_groups + ); + let offsets = &base.dynamic_offsets[..num_dynamic_offsets as usize]; base.dynamic_offsets = &base.dynamic_offsets[num_dynamic_offsets as usize..]; diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 83ab55451c..a06c337ad4 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -157,6 +157,13 @@ impl Global { num_dynamic_offsets, bind_group_id, } => { + assert!( + (index as u32) < cmb.limits.max_bind_groups, + "Bind group index {0} is out of range 0..{1} provided by requested max_bind_group limit {1}", + index, + cmb.limits.max_bind_groups + ); + let offsets = &base.dynamic_offsets[..num_dynamic_offsets as usize]; base.dynamic_offsets = &base.dynamic_offsets[num_dynamic_offsets as usize..]; diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 23314e2a94..cb5f6ae173 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -875,6 +875,13 @@ impl Global { num_dynamic_offsets, bind_group_id, } => { + assert!( + (index as u32) < device.limits.max_bind_groups, + "Bind group index {0} is out of range 0..{1} provided by requested max_bind_group limit {1}", + index, + device.limits.max_bind_groups + ); + let offsets = &base.dynamic_offsets[..num_dynamic_offsets as usize]; base.dynamic_offsets = &base.dynamic_offsets[num_dynamic_offsets as usize..];