CVE-2021-29597: TensorFlow Division by Zero Vulnerability
Summary
CVE-2021-29597: TensorFlow is an end-to-end open source platform for machine learning. Affects tensorflow across 5 version ranges.
< 2.1.4
>= 2.2.0, < 2.2.3
>= 2.3.0, < 2.3.3
>= 2.4.0, < 2.4.2
< 6d36ba65577006affb272335b7c1abd829010708
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-29597 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. TensorFlow is widely used in various industries and research domains for tasks such as image recognition, natural language processing, and recommendation systems. However, a vulnerability has been identified in the implementation of the SpaceToBatchNd TFLite operator, which can lead to a division by zero error.
Vulnerability Detail
The vulnerability in TensorFlow arises from a flaw in the SpaceToBatchNd TFLite operator. An attacker can exploit this vulnerability by crafting a model in such a way that one dimension of the block input is set to 0, causing the corresponding value in block_shape to also be 0. This triggers a division by zero error during the execution of the operator. The impact of this vulnerability can vary depending on the specific usage scenario, but it has the potential to cause crashes, unexpected behavior, or even enable attackers to execute arbitrary code.
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, if upgrading to a fixed version is not immediately feasible, you can manually validate the input dimensions and block shapes before invoking the SpaceToBatchNd operator. By ensuring that none of the dimensions or block shapes are set to 0, you can prevent the division by zero error. Here is an example of how to perform this validation in Python:
block_shape = [2, 0, 3]
input_shape = [6, 12, 18]
if any(dim == 0 for dim in block_shape):
raise ValueError('Block shape cannot contain zero dimensions.')
if any(dim % bs != 0 for dim, bs in zip(input_shape, block_shape)):
raise ValueError('Input shape dimensions must be divisible by corresponding block shape dimensions.')
# Invoke the SpaceToBatchNd operator
Conclusion
In conclusion, the TensorFlow SpaceToBatchNd operator is vulnerable to a division by zero error, which can have various negative consequences. It is crucial to upgrade to the fixed versions of TensorFlow to mitigate this vulnerability. Additionally, implementing the provided workaround can serve as a temporary measure until the upgrade is performed. For further support and assistance in vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for tensorflow →
FAQ
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 SpaceToBatchNd operator is a TFLite operator in TensorFlow that rearranges data in a tensor by spatially partitioning it into blocks and interleaving the partitions.
An attacker can exploit this vulnerability by crafting a model with a block input dimension set to 0, causing a division by zero error during the execution of the SpaceToBatchNd operator.
The impact of this vulnerability can vary depending on the specific usage scenario. It can lead to crashes, unexpected behavior, or even enable attackers to execute arbitrary code.
To fix this vulnerability, it is recommended to upgrade to one of the fixed versions of TensorFlow: TensorFlow 2.5.0, TensorFlow 2.4.2, TensorFlow 2.3.3, TensorFlow 2.2.3, or TensorFlow 2.1.4.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.