未验证 提交 92aa92fa 编写于 作者: W wanghuancoder 提交者: GitHub

fix security bug (#55866)

* fix security bug
上级 6d7efd09
......@@ -2272,7 +2272,19 @@ void ModeInferMeta(const MetaTensor& x,
input_dims.size(),
0,
errors::InvalidArgument("input of ModeOp must have >= 0d shape"));
if (axis < 0) axis += dim_size;
if (axis < 0) {
axis += dim_size;
if (dim_size != 0) {
PADDLE_ENFORCE_GE(axis,
0,
phi::errors::InvalidArgument(
"the axis must be [-%d, %d), but received %d .",
dim_size,
dim_size,
axis - dim_size));
}
}
std::vector<int64_t> dimvec;
for (int64_t i = 0; i < axis; i++) {
dimvec.emplace_back(input_dims[i]);
......
......@@ -1245,21 +1245,6 @@ class TestSundryAPI(unittest.TestCase):
self.assertEqual(x1.grad.shape, [5])
def test_mode(self):
# 1) x is 0D
x = paddle.randn([])
x.stop_gradient = False
out, index = paddle.mode(x)
out.backward()
self.assertEqual(out.shape, [])
self.assertEqual(out, x)
self.assertEqual(index.shape, [])
self.assertEqual(index, 0)
self.assertEqual(x.grad.shape, [])
self.assertEqual(x.grad, 1.0)
# 2) x is 1D
x1 = paddle.randn([5])
x1.stop_gradient = False
out1, index1 = paddle.mode(x1)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册