CVE-2021-29589: TensorFlow - Division by Zero Error in GatherNd TFLite Operator
Summary
CVE-2021-29589: TensorFlow is an end-to-end open source platform for machine learning. Affects tensorflow across 5 version ranges.
>= 2.2.0, < 2.3.0rc0
< 2.2.0rc0
>= 2.3.0, < 2.3.4
>= 2.4.0, < 2.4.3
< 8e45822aa0b9f5df4b4c64f221e64dc930a70a9d
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-29589 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 end-to-end open source platform for machine learning. It provides a comprehensive ecosystem of tools, libraries, and resources for developing and deploying machine learning models. The GatherNd TFLite operator is a reference implementation in TensorFlow that allows gathering elements from multiple tensors based on indices. This operator is used in various machine learning tasks and workflows.
Vulnerability Detail
The reference implementation of the GatherNd TFLite operator in TensorFlow is vulnerable to a division by zero error. This vulnerability arises when the params input tensor is empty, resulting in a zero value for at least one dimension of the params_shape.Dims(.). When this occurs, a division operation is performed, leading to a division by zero error. An attacker can exploit this vulnerability by crafting a malicious model that triggers the division by zero error. The impact of this vulnerability can range from denial of service to potential code execution.
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.2.0rc02.2.0rc0pip install --upgrade "tensorflow==2.2.0rc0" -
>= 2.2.0, < 2.3.0rc02.3.0rc0pip install --upgrade "tensorflow==2.3.0rc0" -
>= 2.3.0, < 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"
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, you can validate the input tensors before using the GatherNd TFLite operator to ensure that the params input tensor is not empty. This can be done by checking the shape of the params tensor and ensuring that it has at least one element in each dimension. Here is an example code snippet in Python:
import tensorflow as tf
params = ... # your input tensor
if tf.size(params) == 0:
# Handle empty tensor case
...
else:
# Use GatherNd TFLite operator
...
Conclusion
In conclusion, the GatherNd TFLite operator in TensorFlow is vulnerable to a division by zero error when the params input tensor is empty. This vulnerability can have serious consequences, including denial of service and potential code execution. It is crucial to update your TensorFlow installation to a fixed version or apply the available backported fixes to mitigate this vulnerability. For further support and assistance in vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for tensorflow →
FAQ
TensorFlow is an open source platform for machine learning that provides a comprehensive set of tools and resources for developing and deploying machine learning models.
The GatherNd TFLite operator is a reference implementation in TensorFlow that allows gathering elements from multiple tensors based on indices. It is commonly used in various machine learning tasks and workflows.
The division by zero vulnerability occurs when the params input tensor in the GatherNd TFLite operator is empty, resulting in a zero value for at least one dimension of the params_shape.Dims(.). This leads to a division operation that triggers the division by zero error.
The impact of this vulnerability can range from denial of service to potential code execution. An attacker can exploit this vulnerability by crafting a malicious model that triggers the division by zero error.
To fix this vulnerability, it is recommended to upgrade your TensorFlow installation to version 2.5.0 or later. Alternatively, you can use one of the backported fixes available for TensorFlow versions 2.4.2, 2.3.3, 2.2.3, and 2.1.4.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.