CVE-2021-29595: TensorFlow DepthToSpace TFLite Operator Division by Zero Vulnerability
Summary
CVE-2021-29595: 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.4
>= 2.4.0, < 2.4.3
< 106d8f4fb89335a2c52d7c895b7a7485465ca8d9
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-29595 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 community resources that enable researchers and developers to build and deploy machine learning models. TensorFlow is widely used in various domains, including computer vision, natural language processing, and reinforcement learning. The DepthToSpace TFLite operator is a component of TensorFlow that rearranges data from depth into blocks of spatial data. This operator is used in many machine learning models to perform tasks such as upsampling and feature extraction.
Vulnerability Detail
The implementation of the DepthToSpace TFLite operator in TensorFlow is vulnerable to a division by zero error. The specific vulnerability occurs in the depth_to_space.cc file (https://github.com/tensorflow/tensorflow/blob/0d45ea1ca641b21b73bcf9c00e0179cda284e7e7/tensorflow/lite/kernels/depth_to_space.cc#L63-L69) where a division operation is performed without checking if the divisor, params->block_size, is zero. An attacker can exploit this vulnerability by crafting a malicious model that sets params->block_size to zero. When the model is executed, a division by zero error will occur, leading to a crash or potentially allowing the attacker 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.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 modify the affected code in the depth_to_space.cc file to include a check for a zero divisor before performing the division operation. Here is an example of the modified code:
if (params->block_size != 0) {
// Perform division operation
...
} else {
// Handle the case when block_size is zero
...
}
Conclusion
The DepthToSpace TFLite operator in TensorFlow is vulnerable to a division by zero error, which can be exploited by an attacker to crash the application or execute arbitrary code. The issue has been addressed in TensorFlow 2.5.0 and will also be patched in earlier versions. Users are advised to update their TensorFlow installations to the latest patched version and regularly check for updates to ensure the security of their machine learning models. For further support on 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 ecosystem of tools and libraries for building and deploying machine learning models.
The DepthToSpace TFLite operator is a component of TensorFlow that rearranges data from depth into blocks of spatial data. It is commonly used in machine learning models for tasks such as upsampling and feature extraction.
This vulnerability allows an attacker to craft a malicious model that triggers a division by zero error in the DepthToSpace TFLite operator. This can lead to a crash or potentially allow the attacker to execute arbitrary code.
The vulnerability affects TensorFlow versions 2.1.4 and above, including versions 2.2.x, 2.3.x, and 2.4.x.
Users should update their TensorFlow installations to the latest patched version as soon as it becomes available. Regularly checking for updates and applying them promptly is recommended to ensure the security and stability of machine learning models.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.