fix oob read access in GatherBlockQuantized#28718
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes potential out-of-bounds reads in the WebGPU GatherBlockQuantized shader when indices fall outside the gather-axis range. Since the indices live on the GPU, the check is performed inside the shader (rather than on CPU) to avoid a host copy; invalid indices simply produce zero outputs.
Changes:
- Compute
gather_axis_dimonce, then bounds-check the (possibly negative-adjusted)indexand write0+ early return on OOB. - Add a WebGPU regression test exercising both positive (
2) and negative (-3) out-of-range indices for int32 and int64 index types on 2-bit/uint8 data.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| onnxruntime/contrib_ops/webgpu/quantization/gather_block_quantized.cc | Adds shader-side bounds check after negative-index normalization; OOB lanes write 0 and return. |
| onnxruntime/test/contrib_ops/gather_block_quantized_op_test.cc | New WebGpu_InvalidIndices_2Bits_Uint8 test covering invalid indices for both int32 and int64 index tensors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
xadupre
approved these changes
Jun 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GatherBlockQuantized shader could read oob for ill formed indicies.
The correct solution would be to throw and exception but the indicies input sits on gpu and we don't want to take the performance hit by copying it to cpu.
Instead, we only check inside the shader to not read oob.