fix(core): Add some missing validity checks (#9913)

This commit is contained in:
Andy Leiserson authored and GitHub committed 2026-07-21 07:36:40 -04:00
1 parent 0eb5b623df
commit c97d22fff4
5 files changed
+62 -7

No files matched your search

+51 -3
View File
@@ -1,11 +1,11 @@
use wgpu_test::{fail, gpu_test, valid, GpuTestConfiguration, GpuTestInitializer, TestParameters};
pub fn all_tests(vec: &mut Vec<GpuTestInitializer>) {
vec.extend([BAD_BUFFER, BAD_TEXTURE]);
vec.extend([BAD_BUFFER_MAP, BAD_TEXTURE_CREATE_VIEW, BAD_TEXTURE_WRITE]);
}
#[gpu_test]
static BAD_BUFFER: GpuTestConfiguration = GpuTestConfiguration::new()
static BAD_BUFFER_MAP: GpuTestConfiguration = GpuTestConfiguration::new()
.parameters(TestParameters::default().enable_noop())
.run_sync(|ctx| {
// Create a buffer with bad parameters and call a few methods.
@@ -38,7 +38,7 @@ static BAD_BUFFER: GpuTestConfiguration = GpuTestConfiguration::new()
});
#[gpu_test]
static BAD_TEXTURE: GpuTestConfiguration = GpuTestConfiguration::new()
static BAD_TEXTURE_CREATE_VIEW: GpuTestConfiguration = GpuTestConfiguration::new()
.parameters(TestParameters::default().enable_noop())
.run_sync(|ctx| {
let texture = fail(
@@ -72,3 +72,51 @@ static BAD_TEXTURE: GpuTestConfiguration = GpuTestConfiguration::new()
valid(&ctx.device, || texture.destroy());
valid(&ctx.device, || texture.destroy());
});
#[gpu_test]
static BAD_TEXTURE_WRITE: GpuTestConfiguration = GpuTestConfiguration::new()
.parameters(TestParameters::default().enable_noop())
.run_sync(|ctx| {
let texture = fail(
&ctx.device,
|| {
ctx.device.create_texture(&wgpu::TextureDescriptor {
label: None,
size: wgpu::Extent3d {
width: 256,
height: 256,
depth_or_array_layers: 1,
},
mip_level_count: 5888,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8Unorm,
usage: wgpu::TextureUsages::COPY_DST,
view_formats: &[],
})
},
Some("mip level count"),
);
fail(
&ctx.device,
|| {
ctx.queue.write_texture(
wgpu::TexelCopyTextureInfo {
texture: &texture,
mip_level: 255,
origin: wgpu::Origin3d::ZERO,
aspect: wgpu::TextureAspect::All,
},
&[0u8; 4],
wgpu::TexelCopyBufferLayout::default(),
wgpu::Extent3d {
width: 1,
height: 1,
depth_or_array_layers: 1,
},
);
},
Some("Texture with '' label is invalid"),
);
});
+4
View File
@@ -922,6 +922,8 @@ impl Queue {
self.same_device_as(dst.as_ref())?;
dst.check_valid()?;
dst.check_usage(wgt::TextureUsages::COPY_DST)
.map_err(TransferError::MissingTextureUsage)?;
@@ -1171,6 +1173,8 @@ impl Queue {
aspect: destination.aspect,
};
dst.check_valid()?;
if !conv::is_valid_external_image_copy_dst_texture_format(dst.desc.format) {
return Err(
TransferError::ExternalCopyToForbiddenTextureFormat(dst.desc.format).into(),
+1
View File
@@ -3818,6 +3818,7 @@ impl Device {
use crate::binding_model::CreateBindGroupError as Error;
view.same_device(self)?;
view.check_valid()?;
let internal_use = self.texture_use_parameters(binding, decl, view, "SampledTexture")?;
used.views.insert_single(view.clone(), internal_use);
+1 -1
View File
@@ -2645,7 +2645,7 @@ impl QuerySet {
desc: desc.clone().map_label(|_| ()),
initialized_slots: Mutex::new(
rank::QUERY_SET_INITIALIZED_SLOTS,
bit_vec::BitVec::from_elem(desc.count as usize, false),
bit_vec::BitVec::new(),
),
device,
})
+5 -3
View File
@@ -177,15 +177,17 @@ impl Extent3d {
#[must_use]
pub fn mip_level_size(&self, level: u32, dim: TextureDimension) -> Self {
Self {
width: u32::max(1, self.width >> level),
width: u32::max(1, self.width.unbounded_shr(level)),
height: match dim {
TextureDimension::D1 => 1,
_ => u32::max(1, self.height >> level),
_ => u32::max(1, self.height.unbounded_shr(level)),
},
depth_or_array_layers: match dim {
TextureDimension::D1 => 1,
TextureDimension::D2 => self.depth_or_array_layers,
TextureDimension::D3 => u32::max(1, self.depth_or_array_layers >> level),
TextureDimension::D3 => {
u32::max(1, self.depth_or_array_layers.unbounded_shr(level))
}
},
}
}