[go: nahoru, domu]

Skip to content

Commit

Permalink
Fix tf.raw_ops.ImageProjectiveTransformV2 vulnerability with large ou…
Browse files Browse the repository at this point in the history
…tput_shape. (tensorflow#57994)

Note: This fix will have to be cherry picked in r2.10, r2.9, and r2.8.
PiperOrigin-RevId: 479125772
  • Loading branch information
poulsbo committed Oct 6, 2022
1 parent 36df736 commit 1824fc1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
9 changes: 5 additions & 4 deletions tensorflow/core/kernels/image/image_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ void DoImageProjectiveTransformOp(OpKernelContext* ctx,
}

Tensor* output_t;
TensorShape output_shape;
OP_REQUIRES_OK(
ctx, ctx->allocate_output(0,
TensorShape({images_t.dim_size(0), out_height,
out_width, images_t.dim_size(3)}),
&output_t));
ctx, TensorShape::BuildTensorShape({images_t.dim_size(0), out_height,
out_width, images_t.dim_size(3)},
&output_shape));
OP_REQUIRES_OK(ctx, ctx->allocate_output(0, output_shape, &output_t));
auto output = output_t->tensor<T, 4>();
auto images = images_t.tensor<T, 4>();
auto transform = transform_t.matrix<float>();
Expand Down
23 changes: 23 additions & 0 deletions tensorflow/python/ops/image_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2335,6 +2335,29 @@ def testInvalidInput(self):
self.evaluate(v)


class ImageProjectiveTransformV2(test_util.TensorFlowTestCase):

def testShapeTooLarge(self):
interpolation = "BILINEAR"
fill_mode = "REFLECT"
images = constant_op.constant(
0.184634328, shape=[2, 5, 8, 3], dtype=dtypes.float32)
transforms = constant_op.constant(
0.378575385, shape=[2, 8], dtype=dtypes.float32)
output_shape = constant_op.constant([1879048192, 1879048192],
shape=[2],
dtype=dtypes.int32)
with self.assertRaisesRegex(errors.InvalidArgumentError,
r"Encountered overflow when multiplying"):
self.evaluate(
gen_image_ops.ImageProjectiveTransformV2(
images=images,
transforms=transforms,
output_shape=output_shape,
interpolation=interpolation,
fill_mode=fill_mode))


class InternalPadToBoundingBoxTest(test_util.TensorFlowTestCase,
parameterized.TestCase):

Expand Down

0 comments on commit 1824fc1

Please sign in to comment.