Skip to content

Commit

Permalink
Merge pull request #49410 from geetachavan1/cherrypicks_8Y18M
Browse files Browse the repository at this point in the history
Fix overflow CHECK issue with `tf.raw_ops.DrawBoundingBoxes`.
  • Loading branch information
mihaimaruseac committed May 21, 2021
2 parents 8f73553 + 65edfe1 commit 6e8a5c5
Showing 1 changed file with 36 additions and 12 deletions.
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

0 comments on commit 6e8a5c5

Please sign in to comment.