Validate index formats in SetIndexBuffer
Fuzzer discovered that it was possible to send invalid IndexFormats to SetIndexBuffer and cause IndexFormatSize to hit an UNREACHABLE(). This validates that the passed format is part of the enum before doing any further operations on it. Bug: 1254571 Change-Id: I1e4075f8d26afdb8e4bcae3cfc72e6219ff28f78 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/65610 Commit-Queue: Brandon Jones <bajones@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
parent
2f1d02b94b
commit
bb417ace11
|
@ -244,6 +244,8 @@ namespace dawn_native {
|
|||
DAWN_TRY(GetDevice()->ValidateObject(buffer));
|
||||
DAWN_TRY(ValidateCanUseAs(buffer, wgpu::BufferUsage::Index));
|
||||
|
||||
DAWN_TRY(ValidateIndexFormat(format));
|
||||
|
||||
DAWN_INVALID_IF(format == wgpu::IndexFormat::Undefined,
|
||||
"Index format must be specified");
|
||||
|
||||
|
|
|
@ -58,6 +58,21 @@ TEST_F(IndexBufferValidationTest, UndefinedIndexFormat) {
|
|||
ASSERT_DEVICE_ERROR(encoder.Finish());
|
||||
}
|
||||
|
||||
// Test that an invalid index format is disallowed.
|
||||
TEST_F(IndexBufferValidationTest, InvalidIndexFormat) {
|
||||
wgpu::BufferDescriptor bufferDesc;
|
||||
bufferDesc.usage = wgpu::BufferUsage::Index;
|
||||
bufferDesc.size = 256;
|
||||
wgpu::Buffer buffer = device.CreateBuffer(&bufferDesc);
|
||||
|
||||
DummyRenderPass renderPass(device);
|
||||
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
|
||||
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass);
|
||||
pass.SetIndexBuffer(buffer, static_cast<wgpu::IndexFormat>(404));
|
||||
pass.EndPass();
|
||||
ASSERT_DEVICE_ERROR(encoder.Finish());
|
||||
}
|
||||
|
||||
// Test that for OOB validation of index buffer offset and size.
|
||||
TEST_F(IndexBufferValidationTest, IndexBufferOffsetOOBValidation) {
|
||||
wgpu::BufferDescriptor bufferDesc;
|
||||
|
|
Loading…
Reference in New Issue