VYPR
Moderate severityNVD Advisory· Published Aug 12, 2021· Updated Aug 4, 2024

Division by zero in TensorFlow Lite `tf.raw_ops.UnravelIndex`

CVE-2021-37668

Description

TensorFlow is an end-to-end open source platform for machine learning. In affected versions an attacker can cause denial of service in applications serving models using tf.raw_ops.UnravelIndex by triggering a division by 0. The implementation does not check that the tensor subsumed by dims is not empty. Hence, if one element of dims is 0, the implementation does a division by 0. We have patched the issue in GitHub commit a776040a5e7ebf76eeb7eb923bf1ae417dd4d233. The fix will be included in TensorFlow 2.6.0. We will also cherrypick this commit on TensorFlow 2.5.1, TensorFlow 2.4.3, and TensorFlow 2.3.4, as these are also affected and still in supported range.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
tensorflowPyPI
< 2.3.42.3.4
tensorflowPyPI
>= 2.4.0, < 2.4.32.4.3
tensorflowPyPI
>= 2.5.0, < 2.5.12.5.1
tensorflow-cpuPyPI
< 2.3.42.3.4
tensorflow-cpuPyPI
>= 2.4.0, < 2.4.32.4.3
tensorflow-cpuPyPI
>= 2.5.0, < 2.5.12.5.1
tensorflow-gpuPyPI
< 2.3.42.3.4
tensorflow-gpuPyPI
>= 2.4.0, < 2.4.32.4.3
tensorflow-gpuPyPI
>= 2.5.0, < 2.5.12.5.1

Affected products

1

Patches

1
a776040a5e7e

Disallow dims input of 0 in tf.raw_ops.UnravelIndex

https://github.com/tensorflow/tensorflowLaura PakJul 12, 2021via ghsa
2 files changed · +9 1
  • tensorflow/core/kernels/unravel_index_op.cc+8 0 modified
    @@ -53,6 +53,14 @@ class UnravelIndexOp : public OpKernel {
                                     dims_tensor.shape().DebugString(), "\""));
     
         auto dims = dims_tensor.vec<Tidx>();
    +    // Make sure dims does not contain a zero
    +    for (int i = 0; i < dims.size(); i++) {
    +      OP_REQUIRES(
    +          ctx, dims(i) != 0,
    +          errors::InvalidArgument("Input dims cannot contain a dim of zero, "
    +                                  "but dims contains zero at index ",
    +                                  i));
    +    }
     
         // Chek to make sure indices is not out of boundary
         Eigen::Tensor<Tidx, 0, Eigen::RowMajor> dims_prod_eigen = dims.prod();
    
  • tensorflow/python/kernel_tests/array_ops_test.py+1 1 modified
    @@ -1575,7 +1575,7 @@ def testUnravelIndexZeroDim(self):
         with self.cached_session():
           for dtype in [dtypes.int32, dtypes.int64]:
             with self.assertRaisesRegex(errors.InvalidArgumentError,
    -                                    "index is out of bound as with dims"):
    +                                    "dims cannot contain a dim of zero"):
               indices = constant_op.constant([2, 5, 7], dtype=dtype)
               dims = constant_op.constant([3, 0], dtype=dtype)
               self.evaluate(array_ops.unravel_index(indices=indices, dims=dims))
    

Vulnerability mechanics

Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

7

News mentions

0

No linked articles in our index yet.