CVE-2021-29549: Division by 0 in TensorFlow
Summary
CVE-2021-29549: Division by 0 in QuantizedAdd. Affects tensorflow across 4 version ranges.
< 2.1.4
>= 2.2.0, < 2.2.3
>= 2.3.0, < 2.3.3
>= 2.4.0, < 2.4.2
Fixed in 4 releases; the minimum fixed version depends on the release line you run. How to fix ↓
Also tracked for
- tensorflow · Bitnami
- tensorflow-cpu · PyPI
- tensorflow-gpu · PyPI
The same CVE-2021-29549 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 developed by Google. It provides a comprehensive ecosystem of tools, libraries, and community resources for building and deploying machine learning models. TensorFlow supports various platforms and is widely used in both research and production environments. However, a vulnerability has been discovered in TensorFlow that can lead to a runtime division by zero error and denial of service.
Vulnerability Detail
The vulnerability, identified as CVE-2021-29549, affects the tf.raw_ops.QuantizedAdd function in TensorFlow. An attacker can exploit this vulnerability by providing specific input values that trigger a division by zero error during the execution of the function. This can result in a denial of service, causing the affected TensorFlow application to crash or become unresponsive. The vulnerability arises from a modulo operation in the implementation of QuantizedAdd that does not validate the divisor, allowing a user to set the divisor to zero.
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.1.42.1.4pip install --upgrade "tensorflow==2.1.4" -
>= 2.2.0, < 2.2.32.2.3pip install --upgrade "tensorflow==2.2.3" -
>= 2.3.0, < 2.3.32.3.3pip install --upgrade "tensorflow==2.3.3" -
>= 2.4.0, < 2.4.22.4.2pip install --upgrade "tensorflow==2.4.2"
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 temporary workaround, users can ensure that the input values provided to the tf.raw_ops.QuantizedAdd function do not trigger a division by zero error. This can be achieved by validating the input values and ensuring that the divisor is not set to zero. Here is an example of how to validate the input values in Python:
import tensorflow as tf
x = tf.constant([68, 228], shape=[2, 1], dtype=tf.quint8)
y = tf.constant([], shape=[2, 0], dtype=tf.quint8)
min_x = tf.constant(10.723421015884028)
max_x = tf.constant(15.19578006631113)
min_y = tf.constant(-5.539003866682977)
max_y = tf.constant(42.18819949559947)
if min_x != 0 and max_x != 0 and min_y != 0 and max_y != 0:
tf.raw_ops.QuantizedAdd(x=x, y=y, min_x=min_x, max_x=max_x, min_y=min_y, max_y=max_y)
else:
print('Invalid input values. Please ensure that the divisor is not set to zero.')
By validating the input values, the division by zero error can be avoided.
Conclusion
In conclusion, the CVE-2021-29549 vulnerability in TensorFlow can lead to a division by zero error and denial of service. Users are advised to update their TensorFlow installations to the patched versions and validate input values to prevent the vulnerability. For further support on vulnerability remediation, you can contact DevNack.com.
See every vulnerability recorded for tensorflow →
FAQ
TensorFlow is an open-source machine learning framework developed by Google. It provides tools and libraries for building and deploying machine learning models.
The vulnerability can lead to a runtime division by zero error and denial of service in TensorFlow applications, causing them to crash or become unresponsive.
To fix this vulnerability, update your TensorFlow installation to one of the patched versions: TensorFlow 2.5.0, TensorFlow 2.4.2, TensorFlow 2.3.3, TensorFlow 2.2.3, or TensorFlow 2.1.4.
Yes, as a temporary workaround, you can validate the input values to ensure that the divisor is not set to zero. Refer to the provided code example for more details.
For more information, you can refer to the TensorFlow security guide and the GitHub advisory database, which provide details on the vulnerability and its fix.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.