wgpu icon indicating copy to clipboard operation
wgpu copied to clipboard

Fix calculation/validation of layer/mip ranges in create_texture_view

Open nical opened this issue 2 years ago • 1 comments

Back with some more validation fixes.

Checklist

  • [x] Run cargo clippy.
  • [x] Add change to CHANGELOG.md. See simple instructions inside file.

Connections

https://bugzilla.mozilla.org/show_bug.cgi?id=1780057

Description

The previous code was doing "selector.layers = base_layer .. count" instead of "base_layer .. base_layer + count" which looked dubious. Same thing for the mip range. It was also not taking the base layer count when in requested_layer_count when the texture was not a texture array which led to invalid ranges and underflow when asking for a non-zero base layer with a (non-array) 2d texture.

The fix consists in:

  • writing the ranges as base .. base + count
  • always taking the provided base layer into account in the requested layer count even where it doesn't make sense (since it will ensure validation catches the error).

Testing

None

nical avatar Aug 11 '22 14:08 nical

Added a commit that checks for integer overflow because the fuzzer told me I had to.

nical avatar Aug 11 '22 15:08 nical