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

Address QuantizeAndDequantizeV* heap oob. Added additional checks fo… #52743

Merged
merged 1 commit into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
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
20 changes: 16 additions & 4 deletions tensorflow/core/ops/array_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2854,7 +2854,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 @@ -2886,7 +2889,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 @@ -2914,7 +2920,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 @@ -2947,7 +2956,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