CVE-2021-29587: TensorFlow SpaceToDepth TFLite Operator Division by Zero Vulnerability
Summary
CVE-2021-29587: TensorFlow is an end-to-end open source platform for machine learning. Affects tensorflow across 5 version ranges.
< 0d45ea1ca641b21b73bcf9c00e0179cda284e7e7
>= 2.2.0, < 2.3.0rc0
< 2.2.0rc0
>= 2.3.0, < 2.3.4
>= 2.4.0, < 2.4.3
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-29587 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 SpaceToDepth TFLite operator is used to rearrange data by spatially partitioning it into blocks and then concatenating them. This operator is an integral part of TensorFlow's deep learning framework and is widely used in various applications.
Vulnerability Detail
The vulnerability (CVE-2021-29587) exists in the Prepare step of the SpaceToDepth TFLite operator in TensorFlow. The operator fails to check for a zero value before performing a division operation. An attacker can exploit this by crafting a malicious model that sets the block_size parameter to zero. When the model is executed, it triggers a division by zero error, leading to a potential denial-of-service (DoS) condition or other unexpected behavior. The vulnerability affects TensorFlow versions 2.1.4 and below, 2.2.3 and below, 2.3.3 and below, and 2.4.2 and below.
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 temporary workaround, users can manually check and ensure that the block_size parameter used in the SpaceToDepth TFLite operator is not set to zero. This can be done by inspecting the model code or configuration files. If a zero value is found, it should be modified to a non-zero value to mitigate the vulnerability. Here is an example of how the block_size parameter can be set correctly:
import tensorflow as tf
block_size = 2
# Create the SpaceToDepth layer
space_to_depth_layer = tf.keras.layers.Lambda(lambda x: tf.nn.space_to_depth(x, block_size))
Conclusion
The TensorFlow SpaceToDepth TFLite Operator Division by Zero Vulnerability (CVE-2021-29587) poses a risk to TensorFlow applications using affected versions. It allows an attacker to craft a malicious model that triggers a division by zero error, potentially leading to a denial-of-service (DoS) condition or other unexpected behavior. Users are strongly advised to upgrade their TensorFlow installations to version 2.5.0 or later to mitigate this vulnerability. Alternatively, users on older versions can upgrade to the respective fixed versions. For further support and assistance in vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for tensorflow →
FAQ
The vulnerability allows an attacker to craft a malicious model that triggers a division by zero error in the SpaceToDepth TFLite operator. This can lead to a denial-of-service (DoS) condition or other unexpected behavior in TensorFlow applications.
The vulnerability affects TensorFlow versions 2.1.4 and below, 2.2.3 and below, 2.3.3 and below, and 2.4.2 and below. Users on these versions should upgrade to the fixed versions.
Yes, the vulnerability has been patched in TensorFlow 2.5.0. The fix has also been backported to TensorFlow versions 2.4.3, 2.3.4, 2.2.0rc0, and 2.1.4.
To upgrade your TensorFlow installation, follow the official upgrade instructions provided by TensorFlow. Make sure to upgrade to version 2.5.0 or later to fix this vulnerability.
Yes, as a temporary workaround, users can manually check and ensure that the block_size parameter used in the SpaceToDepth TFLite operator is not set to zero. Modify any zero values to a non-zero value to mitigate the vulnerability.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.