CVE-2021-41197: Integer Overflow or Wraparound (CWE-190)
value: TensorFlow is an open source platform for machine learning. In affected versions TensorFlow allows tensor to have a large number of dimensions and each dimension can be as large as desired. However, the total number of elements in a tensor must fit within an `int64_t`. If an overflow occurs, `MultiplyWithoutOverflow` would return a negative result. In the majority of TensorFlow codebase this then results in a `CHECK`-failure. Newer constructs exist which return a `Status` instead of crashing the binary. This is similar to CVE-2021-29584. The fix will be included in TensorFlow 2.7.0. We will also cherrypick this commit on TensorFlow 2.6.1, TensorFlow 2.5.2, and TensorFlow 2.4.4, as these are also affected and still in supported range.
CWE description: The product performs a calculation that can
         produce an integer overflow or wraparound when the logic
         assumes that the resulting value will always be larger than
         the original value. This occurs when an integer value is
         incremented to a value that is too large to store in the
         associated representation. When this occurs, the value may
         become a very small or negative number.
CVSS v3 base score: 5.5
Published: 2021-11-05T20:15Z
Repository: https://github.com/tensorflow/tensorflow
Language: Python
Files changed: tensorflow/python/ops/image_ops_test.py
Commit date: 2021-09-22 16:01:39 -0700
Commit message: Merge pull request #51717 from yongtang:46890-tf.image.pad_to_bounding_box

PiperOrigin-RevId: 398351034
Change-Id: Ia11abe3ab57683ca2efea786fd095338d0c8c3b7

Diff: diff --cc tensorflow/python/ops/image_ops_test.py
index 503de3ad76a3b,8a4c88da87882..5744a9acda943
--- a/tensorflow/python/ops/image_ops_test.py
+++ b/tensorflow/python/ops/image_ops_test.py
@@@ -2291,10 -2291,21 +2291,25 @@@ class PadToBoundingBoxTest(test_util.Te
      with ops.Graph().as_default():
        image = array_ops.placeholder(dtypes.float32, shape=[55, 66, 3])
        y = image_ops.pad_to_bounding_box(image, 0, 0, 55, 66)
        self.assertTrue(y.op.name.startswith("pad_to_bounding_box"))
  
+   def testInvalidInput(self):
+     # Test case for GitHub issue 46890.
++    if test_util.is_xla_enabled():
++      # TODO(b/200850176): test fails with XLA.
++      return
+     with self.session():
+       with self.assertRaises(errors_impl.InternalError):
+         v = image_ops.pad_to_bounding_box(
+             image=np.ones((1, 1, 1)),
+             target_height=5191549470,
+             target_width=5191549470,
 -            offset_height=1, offset_width=1)
++            offset_height=1,
++            offset_width=1)
+         self.evaluate(v)
+ 
  
  class SelectDistortedCropBoxTest(test_util.TensorFlowTestCase):
  
    def _testSampleDistortedBoundingBox(self, image, bounding_box,
                                        min_object_covered, aspect_ratio_range,

Fixed code:    def testInvalidInput(self):
     # Test case for GitHub issue 46890.
+    if test_util.is_xla_enabled():
+      # TODO(b/200850176): test fails with XLA.
+      return
     with self.session():
       with self.assertRaises(errors_impl.InternalError):
         v = image_ops.pad_to_bounding_box(
             image=np.ones((1, 1, 1)),
             target_height=5191549470,
             target_width=5191549470,
+            offset_height=1,
+            offset_width=1)
         self.evaluate(v)