Skip to content

Commit

Permalink
Address QuantizeAndDequantizeV* heap oob. Added additional checks fo…
Browse files Browse the repository at this point in the history
…r the 'axis' attribute.

PiperOrigin-RevId: 402446942
Change-Id: Id2f6b82e4e740d0550329be02621c46466b5a5b9
  • Loading branch information
pkanwar23 authored and tensorflower-gardener committed Oct 12, 2021
1 parent 3bbc2ee commit 7cf73a2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 16 additions & 4 deletions tensorflow/core/ops/array_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2863,7 +2863,10 @@ REGISTER_OP("QuantizeAndDequantizeV2")
ShapeHandle minmax;
TF_RETURN_IF_ERROR(c->WithRank(c->input(1), minmax_rank, &minmax));
TF_RETURN_IF_ERROR(c->Merge(c->input(2), minmax, &minmax));
if (axis != -1) {
if (axis < -1) {
return errors::InvalidArgument("axis should be at least -1, got ",
axis);
} else if (axis != -1) {
ShapeHandle input;
TF_RETURN_IF_ERROR(c->WithRankAtLeast(c->input(0), axis + 1, &input));
DimensionHandle depth;
Expand Down Expand Up @@ -2895,7 +2898,10 @@ REGISTER_OP("QuantizeAndDequantizeV4")
ShapeHandle minmax;
TF_RETURN_IF_ERROR(c->WithRank(c->input(1), minmax_rank, &minmax));
TF_RETURN_IF_ERROR(c->Merge(c->input(2), minmax, &minmax));
if (axis != -1) {
if (axis < -1) {
return errors::InvalidArgument("axis should be at least -1, got ",
axis);
} else if (axis != -1) {
ShapeHandle input;
TF_RETURN_IF_ERROR(c->WithRankAtLeast(c->input(0), axis + 1, &input));
DimensionHandle depth;
Expand Down Expand Up @@ -2923,7 +2929,10 @@ REGISTER_OP("QuantizeAndDequantizeV4Grad")
ShapeHandle minmax;
TF_RETURN_IF_ERROR(c->WithRank(c->input(2), minmax_rank, &minmax));
TF_RETURN_IF_ERROR(c->Merge(c->input(3), minmax, &minmax));
if (axis != -1) {
if (axis < -1) {
return errors::InvalidArgument("axis should be at least -1, got ",
axis);
} else if (axis != -1) {
ShapeHandle input;
TF_RETURN_IF_ERROR(c->WithRankAtLeast(c->input(0), axis + 1, &input));
DimensionHandle depth;
Expand Down Expand Up @@ -2956,7 +2965,10 @@ REGISTER_OP("QuantizeAndDequantizeV3")
ShapeHandle minmax;
TF_RETURN_IF_ERROR(c->WithRank(c->input(1), minmax_rank, &minmax));
TF_RETURN_IF_ERROR(c->Merge(c->input(2), minmax, &minmax));
if (axis != -1) {
if (axis < -1) {
return errors::InvalidArgument("axis should be at least -1, got ",
axis);
} else if (axis != -1) {
ShapeHandle input;
TF_RETURN_IF_ERROR(c->WithRankAtLeast(c->input(0), axis + 1, &input));
DimensionHandle depth;
Expand Down
2 changes: 2 additions & 0 deletions tensorflow/core/ops/array_ops_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,8 @@ TEST(ArrayOpsTest, QuantizeAndDequantizeV2_ShapeFn) {
INFER_ERROR("Shapes must be equal rank, but are 1 and 0", op,
"[1,2,?,4,5];[];[1]");
INFER_ERROR("Shape must be rank 0 but is rank 1", op, "[1,2,?,4,5];[1];[1]");
(*op.node_def.mutable_attr())["axis"].set_i(-2);
INFER_ERROR("axis should be at least -1, got -2", op, "?;?;?");
}

TEST(ArrayOpsTest, SpaceToBatch_ShapeFn) {
Expand Down

0 comments on commit 7cf73a2

Please sign in to comment.