Skip to content

Commit

Permalink
Prevent CHECK-fail/heap OOB in UpperBound and LowerBound
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 387738073
Change-Id: Iee74de95ddad18440d052a75a5a1cb67544f490a
  • Loading branch information
mihaimaruseac authored and tensorflower-gardener committed Jul 30, 2021
1 parent b5cdbf1 commit 42459e4
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 42459e4

Please sign in to comment.