未验证 提交 34bf3d09 编写于 作者: R RedContritio 提交者: GitHub

Fix UFA非法地址访问(UFA illegal address access) of case3: paddle.crop (#49994)

* add range check for crop_kernel

* remove shape negative check

* add unittest
上级 fd5b8eea
......@@ -100,6 +100,16 @@ void CropTensorFunction(const Context& dev_ctx,
out->Resize(out_dims);
dev_ctx.template Alloc<T>(out);
for (size_t i = 0; i < offsets_vec.size(); ++i) {
PADDLE_ENFORCE_GE(
offsets_vec[i],
0,
errors::InvalidArgument("The offsets (%d) of the %uth elements of"
" Op(crop_tensor) "
"should be greater than or "
"equal to 0.",
offsets_vec[i],
i));
PADDLE_ENFORCE_LE(offsets_vec[i] + shape_vec[i],
x_dims[i],
errors::InvalidArgument(
......
......@@ -149,6 +149,13 @@ class TestCropNoneShape(unittest.TestCase):
self.assertEqual(crop.shape, (3, 6, 6))
class TestCropError(unittest.TestCase):
def test_neg_offset_error(self):
with self.assertRaises(ValueError):
x = fluid.data(name='input2', shape=[1], dtype="float32")
out = paddle.crop(x, offsets=[-1])
if __name__ == '__main__':
paddle.enable_static()
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册