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 tf.pad crashes with large paddings #51973

Closed
wants to merge 1 commit into from
Closed
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
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
12 changes: 12 additions & 0 deletions tensorflow/python/kernel_tests/pad_op_test.py
Expand Up @@ -431,6 +431,18 @@ def testCollapseAdjacentNonPaddedDimensions(self):
np.zeros([row[1] for row in paddings_value]),
self.evaluate(right))

def testWithLargePadding(self):
# Test case for GitHub issue 51908.
with self.session():
input_tensor = array_ops.zeros([1, 32, 32, 3], dtype=dtypes.float32)
paddings = [[125106557, 1415887920],
[747509374, 2136925906],
[413308538, 904601717],
[1900762018, 831358864]]
with self.assertRaises((ValueError, errors.InternalError)):
res = array_ops.pad(input_tensor,paddings)
self.evaluate(res)


if __name__ == "__main__":
test.main()