CVE-2021-37636: Floating point exception in TensorFlow
Summary
CVE-2021-37636: Floating point exception in SparseDenseCwiseDiv. Affects tensorflow across 3 version ranges.
< 2.3.4
>= 2.4.0, < 2.4.3
>= 2.5.0, < 2.5.1
Fixed in 2.3.4, 2.4.3 or 2.5.1, depending on the release line you run. How to fix ↓
Also tracked for
- tensorflow · Bitnami
- tensorflow-cpu · PyPI
- tensorflow-gpu · PyPI
The same CVE-2021-37636 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
TensorFlow is an open-source machine learning framework that provides a comprehensive ecosystem of tools, libraries, and resources for developing and deploying machine learning models. It is widely used in various domains, including research, industry, and academia. TensorFlow allows users to build and train neural networks, perform numerical computations, and process large datasets efficiently. However, a vulnerability has been identified in TensorFlow that can lead to a floating point exception.
Vulnerability Detail
The vulnerability, identified as CVE-2021-37636, exists in the implementation of tf.raw_ops.SparseDenseCwiseDiv in TensorFlow. This function is used for element-wise division between a sparse tensor and a dense tensor. The implementation fails to handle the division by zero case, resulting in a floating point exception. An attacker could exploit this vulnerability by providing malicious input data, leading to a division by zero error and potentially causing the application to crash or behave unexpectedly. The impact of this vulnerability is considered moderate, with a CVSS score of 5.5.
How To Fix
Latest published version: 2.21.0 as of 22 Oct 2026
pip install --upgrade "tensorflow==2.21.0"
Upgrading to it may include breaking changes; the versions below are the minimum fixed release for this vulnerability.
If you can't move to the latest
The minimum fixed version depends on the release line you run.
-
< 2.3.42.3.4pip install --upgrade "tensorflow==2.3.4" -
>= 2.4.0, < 2.4.32.4.3pip install --upgrade "tensorflow==2.4.3" -
>= 2.5.0, < 2.5.12.5.1pip install --upgrade "tensorflow==2.5.1"
Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →
Workaround
As a workaround, users can validate the input data before invoking the tf.raw_ops.SparseDenseCwiseDiv function to ensure that no division by zero occurs. This can be done by checking the values of the input tensors and ensuring that the divisor is not zero. Here is an example of how to perform the validation in Python:
import tensorflow as tf
import numpy as np
sp_indices = np.array([[4]])
sp_values = np.array([-400])
sp_shape = np.array([647.])
dense = np.array([0])
if np.any(dense == 0):
raise ValueError('Division by zero is not allowed.')
# Proceed with the division operation
result = tf.raw_ops.SparseDenseCwiseDiv(sp_indices, sp_values, sp_shape, dense)
By performing this validation, the risk of encountering a division by zero error can be mitigated.
Conclusion
In conclusion, the vulnerability identified as CVE-2021-37636 in TensorFlow can lead to a floating point exception when performing element-wise division between a sparse tensor and a dense tensor. The TensorFlow team has released patches to address this vulnerability, and users are advised to update their installations to the latest patched version. A workaround is also available by validating the input data to prevent division by zero. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for tensorflow →
FAQ
TensorFlow is an open-source machine learning framework that provides tools and resources for developing and deploying machine learning models.
The impact of this vulnerability is considered moderate, with a CVSS score of 5.5. It can potentially lead to application crashes or unexpected behavior.
To fix this vulnerability, it is recommended to update TensorFlow to the latest patched version (2.6.0 or later). The fix has also been backported to earlier versions (2.5.1, 2.4.3, and 2.3.4).
Yes, a workaround is available. Users can validate the input data before invoking the vulnerable function to ensure that no division by zero occurs.
For more information, please refer to the TensorFlow security guide and the GitHub advisory for this vulnerability.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.