From 105637914ad44209beffda945040501de1dd371c Mon Sep 17 00:00:00 2001 From: TeslaZhao Date: Tue, 24 Aug 2021 09:58:51 +0800 Subject: [PATCH] Fix a bug of transpose op, about accessing memory out of bounds of the perm param (#35079) --- paddle/fluid/operators/transpose_op.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/paddle/fluid/operators/transpose_op.cc b/paddle/fluid/operators/transpose_op.cc index 95b2c13ff6..da7f824b3a 100644 --- a/paddle/fluid/operators/transpose_op.cc +++ b/paddle/fluid/operators/transpose_op.cc @@ -48,6 +48,12 @@ class TransposeOp : public framework::OperatorWithKernel { std::vector count(axis_size, 0); for (size_t i = 0; i < axis_size; i++) { + PADDLE_ENFORCE_GE(axis[i], 0, + platform::errors::InvalidArgument( + "The axis should be greater than or equal to 0." + "But received %d of axis[%d]", + axis[i], i)); + PADDLE_ENFORCE_EQ( axis[i] < static_cast(axis_size) && ++count[axis[i]] == 1, true, platform::errors::InvalidArgument( -- GitLab