Skip to content

Commit aefec22

Browse files
authored
Fix a bug of strided_slice op, about the axes parameter access memory out of bounds (#35062)
1 parent c3efabe commit aefec22

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

paddle/fluid/operators/strided_slice_op.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ class StridedSliceOp : public framework::OperatorWithKernel {
6262
auto ends_size = ends.size();
6363
auto strides_size = strides.size();
6464

65+
for (size_t i = 0; i < axes.size(); ++i) {
66+
PADDLE_ENFORCE_GE(axes[i], 0,
67+
platform::errors::InvalidArgument(
68+
"The axis should be greater than or equal to 0."
69+
"But received %d of axes[%d]",
70+
axes[i], i));
71+
PADDLE_ENFORCE_LT(
72+
axes[i], in_dims.size(),
73+
platform::errors::InvalidArgument(
74+
"The axes should be less than or equal to input tensor's rank."
75+
"But received %d of axes[%d], input tensor shape [%d]",
76+
axes[i], i, in_dims.size()));
77+
}
78+
6579
if (ctx->HasInputs("StartsTensorList")) {
6680
auto StartsTensorList = ctx->Inputs("StartsTensorList");
6781
PADDLE_ENFORCE_GT(

0 commit comments

Comments
 (0)