Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions paddle/phi/kernels/impl/crop_kernel_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 7 additions & 0 deletions python/paddle/fluid/tests/unittests/test_crop_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ def test_crop_none_shape(self):
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()