CVE-2021-29587: TensorFlow GPU - 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-gpu 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 · PyPI
- tensorflow · PyPI
- tensorflow-cpu · 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. TensorFlow GPU is a variant of TensorFlow that leverages GPU acceleration for faster computation. The SpaceToDepth TFLite operator is used for rearranging data in a tensor by spatially partitioning it into blocks and then concatenating them. This operator is susceptible to a division by zero vulnerability.
Vulnerability Detail
The vulnerability (CVE-2021-29587) arises from the lack of a check for zero before division in the Prepare step of the SpaceToDepth TFLite operator in TensorFlow. An attacker can exploit this vulnerability by crafting a malicious model that sets the params->block_size parameter to zero. When the model is executed, the division by zero occurs, leading to potential crashes, unexpected behavior, or even remote code execution. The vulnerability affects TensorFlow versions 2.1.4 to 2.4.3, as well as TensorFlow GPU versions 0 to 2.4.3.
How To Fix
Latest published version: 2.12.0 as of 22 Oct 2026
pip install --upgrade "tensorflow-gpu==2.12.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-gpu==2.2.0rc0" -
>= 2.2.0, < 2.3.0rc02.3.0rc0pip install --upgrade "tensorflow-gpu==2.3.0rc0" -
>= 2.3.0, < 2.3.42.3.4pip install --upgrade "tensorflow-gpu==2.3.4" -
>= 2.4.0, < 2.4.32.4.3pip install --upgrade "tensorflow-gpu==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 TensorFlow source files. Specifically, the space_to_depth.cc file located at tensorflow/lite/kernels/space_to_depth.cc needs to be edited. The Prepare function should be modified to include a check for zero before performing the division operation. Here is an example of the modified code:
double block_size = params->block_size;
if (block_size == 0) {
// Handle the division by zero case
// Perform necessary actions
} else {
// Perform the division operation
// Continue with the normal execution
}
Conclusion
The division by zero vulnerability in the SpaceToDepth TFLite operator of TensorFlow GPU can be exploited by an attacker to cause crashes, unexpected behavior, or even remote code execution. Users are advised to update their TensorFlow installations to the latest patched version and follow the official documentation for guidance. For further support on vulnerability remediation, contact DevNack.com.
See every vulnerability recorded for tensorflow-gpu →
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 SpaceToDepth TFLite operator is used in TensorFlow to rearrange data in a tensor by spatially partitioning it into blocks and then concatenating them.
The vulnerability occurs because the Prepare step of the SpaceToDepth TFLite operator in TensorFlow does not check for zero before performing the division operation. An attacker can exploit this by setting the params->block_size parameter to zero in a crafted model.
The division by zero vulnerability in the SpaceToDepth TFLite operator can lead to crashes, unexpected behavior, or even remote code execution when a maliciously crafted model is executed.
To fix this vulnerability, it is recommended to update your TensorFlow installation to the latest patched version. Follow the official TensorFlow documentation for instructions on updating the library.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow-gpu.