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 crash of tf.image.pad_to_bounding_box with large input value. #51717

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion tensorflow/core/kernels/pad_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class PadOp : public OpKernel {
errors::InvalidArgument("Paddings must be non-negative: ",
before_d, " ", after_d));
const int64_t size_d = in0.dim_size(d);
output_shape.AddDim(before_d + size_d + after_d);
OP_REQUIRES_OK(
context, output_shape.AddDimWithStatus(before_d + size_d + after_d));
}

// If there is no padding to be done, forward the input to output.
Expand Down
11 changes: 11 additions & 0 deletions tensorflow/python/ops/image_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2293,6 +2293,17 @@ def testNameScope(self):
y = image_ops.pad_to_bounding_box(image, 0, 0, 55, 66)
self.assertTrue(y.op.name.startswith("pad_to_bounding_box"))

def testInvalidInput(self):
# Test case for GitHub issue 46890.
with self.session():
with self.assertRaises(errors_impl.InternalError):
v = image_ops.pad_to_bounding_box(
image=np.ones((1, 1, 1)),
target_height=5191549470,
target_width=5191549470,
offset_height=1, offset_width=1)
self.evaluate(v)


class SelectDistortedCropBoxTest(test_util.TensorFlowTestCase):

Expand Down