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 overflow CHECK issue with tf.raw_ops.DrawBoundingBoxes. #49410

Merged
merged 1 commit into from
May 21, 2021
Merged
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
48 changes: 36 additions & 12 deletions tensorflow/core/kernels/draw_bounding_box_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,46 @@ class DrawBoundingBoxesOp : public OpKernel {

// At this point, {min,max}_box_{row,col}_clamp are inside the
// image.
CHECK_GE(min_box_row_clamp, 0);
CHECK_GE(max_box_row_clamp, 0);
CHECK_LT(min_box_row_clamp, height);
CHECK_LT(max_box_row_clamp, height);
CHECK_GE(min_box_col_clamp, 0);
CHECK_GE(max_box_col_clamp, 0);
CHECK_LT(min_box_col_clamp, width);
CHECK_LT(max_box_col_clamp, width);
OP_REQUIRES(
context, min_box_row_clamp >= 0,
errors::InvalidArgument("Min box row clamp is less than 0."));
OP_REQUIRES(
context, max_box_row_clamp >= 0,
errors::InvalidArgument("Max box row clamp is less than 0."));
OP_REQUIRES(context, min_box_row_clamp <= height,
errors::InvalidArgument(
"Min box row clamp is greater than height."));
OP_REQUIRES(context, max_box_row_clamp <= height,
errors::InvalidArgument(
"Max box row clamp is greater than height."));

OP_REQUIRES(
context, min_box_col_clamp >= 0,
errors::InvalidArgument("Min box col clamp is less than 0."));
OP_REQUIRES(
context, max_box_col_clamp >= 0,
errors::InvalidArgument("Max box col clamp is less than 0."));
OP_REQUIRES(context, min_box_col_clamp <= width,
errors::InvalidArgument(
"Min box col clamp is greater than width."));
OP_REQUIRES(context, max_box_col_clamp <= width,
errors::InvalidArgument(
"Max box col clamp is greater than width."));

// At this point, the min_box_row and min_box_col are either
// in the image or above/left of it, and max_box_row and
// max_box_col are either in the image or below/right or it.
CHECK_LT(min_box_row, height);
CHECK_GE(max_box_row, 0);
CHECK_LT(min_box_col, width);
CHECK_GE(max_box_col, 0);

OP_REQUIRES(
context, min_box_row <= height,
errors::InvalidArgument("Min box row is greater than height."));
OP_REQUIRES(context, max_box_row >= 0,
errors::InvalidArgument("Max box row is less than 0."));
OP_REQUIRES(
context, min_box_col <= width,
errors::InvalidArgument("Min box col is greater than width."));
OP_REQUIRES(context, max_box_col >= 0,
errors::InvalidArgument("Max box col is less than 0."));

// Draw top line.
if (min_box_row >= 0) {
Expand Down