Skip to content

Commit

Permalink
Merge pull request #51265 from tensorflow/mm-cherrypick-42459e4273c2e…
Browse files Browse the repository at this point in the history
…47a3232cc16c4f4fff3b3a35c38-on-r2.4

Prevent CHECK-fail/heap OOB in UpperBound and LowerBound
  • Loading branch information
mihaimaruseac committed Aug 5, 2021
2 parents 5dfc912 + e20d2ed commit 9864122
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tensorflow/core/kernels/searchsorted_op.cc
Expand Up @@ -86,6 +86,10 @@ class UpperBoundOp : public OpKernel {
const Tensor& sorted_inputs_t = ctx->input(0);
const Tensor& values_t = ctx->input(1);

// inputs must be at least a matrix
OP_REQUIRES(
ctx, sorted_inputs_t.shape().dims() >= 2,
errors::InvalidArgument("sorted input argument must be a matrix"));
// must have same batch dim_size for both
OP_REQUIRES(ctx, sorted_inputs_t.dim_size(0) == values_t.dim_size(0),
Status(error::INVALID_ARGUMENT,
Expand Down Expand Up @@ -127,6 +131,10 @@ class LowerBoundOp : public OpKernel {
const Tensor& sorted_inputs_t = ctx->input(0);
const Tensor& values_t = ctx->input(1);

// inputs must be at least a matrix
OP_REQUIRES(
ctx, sorted_inputs_t.shape().dims() >= 2,
errors::InvalidArgument("sorted input argument must be a matrix"));
// must have same batch dim_size for both
OP_REQUIRES(ctx, sorted_inputs_t.dim_size(0) == values_t.dim_size(0),
Status(error::INVALID_ARGUMENT,
Expand Down

0 comments on commit 9864122

Please sign in to comment.