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

Integer division by 0 in sparse reshaping in TensorFlow

CVE-2021-37640

Description

TensorFlow is an end-to-end open source platform for machine learning. In affected versions the implementation of tf.raw_ops.SparseReshape can be made to trigger an integral division by 0 exception. The implementation calls the reshaping functor whenever there is at least an index in the input but does not check that shape of the input or the target shape have both a non-zero number of elements. The reshape functor blindly divides by the dimensions of the target shape. Hence, if this is not checked, code will result in a division by 0. We have patched the issue in GitHub commit 4923de56ec94fff7770df259ab7f2288a74feb41. The fix will be included in TensorFlow 2.6.0. We will also cherrypick this commit on TensorFlow 2.5.1 as this is the other affected version.

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
4923de56ec94

Don't do any work when reshaping 0 elements sparse tensor.

https://github.com/tensorflow/tensorflowMihai MaruseacAug 2, 2021via ghsa
1 file changed · +6 0
  • tensorflow/core/kernels/reshape_util.cc+6 0 modified
    @@ -174,6 +174,12 @@ void ReshapeSparseTensor(OpKernelContext *context,
                                               TensorShape({nnz, output_rank}),
                                               &result_indices));
       if (nnz > 0) {
    +    OP_REQUIRES(
    +        context, dense_size > 0 && product > 0,
    +        errors::InvalidArgument(
    +            "Input tensor has ", nnz, " non zero elements but input shape (",
    +            input_shape.DebugString(), ") or output shape (",
    +            output_shape.DebugString(), ") is empty"));
         OP_REQUIRES_OK(context, functor::ReshapeSparseTensorFunctor<Device>()(
                                     context, input_shape, output_shape,
                                     input_indices_in.matrix<int64>(),
    

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.