Skip to content

Commit 5c0a19b

Browse files
bmehta001Copilot
andcommitted
Validate axes bounds in WebGPU Slice operator
After normalizing negative axes, validate that each axis is within [0, input_rank). Without this check, out-of-range axes could cause out-of-bounds access on the input shape array. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 271446e commit 5c0a19b

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

  • onnxruntime/core/providers/webgpu/tensor

onnxruntime/core/providers/webgpu/tensor/slice.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ Status Slice::ComputeInternal(ComputeContext& context) const {
158158
if (val < 0) {
159159
val += input_rank;
160160
}
161+
ORT_RETURN_IF(val < 0 || val >= static_cast<int64_t>(input_rank),
162+
"Axis value ", axes_raw[i], " is out of range for input rank ", input_rank);
161163
axes_fixed.push_back(static_cast<int32_t>(val));
162164
axes.push_back(static_cast<int32_t>(val));
163165
}

0 commit comments

Comments
 (0)