Integer division by 0 in sparse reshaping in TensorFlow
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.
| Package | Affected versions | Patched versions |
|---|---|---|
tensorflowPyPI | < 2.3.4 | 2.3.4 |
tensorflowPyPI | >= 2.4.0, < 2.4.3 | 2.4.3 |
tensorflowPyPI | >= 2.5.0, < 2.5.1 | 2.5.1 |
tensorflow-cpuPyPI | < 2.3.4 | 2.3.4 |
tensorflow-cpuPyPI | >= 2.4.0, < 2.4.3 | 2.4.3 |
tensorflow-cpuPyPI | >= 2.5.0, < 2.5.1 | 2.5.1 |
tensorflow-gpuPyPI | < 2.3.4 | 2.3.4 |
tensorflow-gpuPyPI | >= 2.4.0, < 2.4.3 | 2.4.3 |
tensorflow-gpuPyPI | >= 2.5.0, < 2.5.1 | 2.5.1 |
Affected products
1- Range: < 2.5.1
Patches
14923de56ec94Don't do any work when reshaping 0 elements sparse tensor.
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- github.com/advisories/GHSA-95xm-g58g-3p88ghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2021-37640ghsaADVISORY
- github.com/pypa/advisory-database/tree/main/vulns/tensorflow-cpu/PYSEC-2021-553.yamlghsaWEB
- github.com/pypa/advisory-database/tree/main/vulns/tensorflow-gpu/PYSEC-2021-751.yamlghsaWEB
- github.com/pypa/advisory-database/tree/main/vulns/tensorflow/PYSEC-2021-262.yamlghsaWEB
- github.com/tensorflow/tensorflow/commit/4923de56ec94fff7770df259ab7f2288a74feb41ghsax_refsource_MISCWEB
- github.com/tensorflow/tensorflow/security/advisories/GHSA-95xm-g58g-3p88ghsax_refsource_CONFIRMWEB
News mentions
0No linked articles in our index yet.