CVE-2021-29587: Division by zero in TFLite's implementation of SpaceToDepth
Summary
CVE-2021-29587: Division by zero in TFLite's implementation of SpaceToDepth. Affects tensorflow across 4 version ranges.
< 2.1.4
>= 2.2.0, < 2.2.3
>= 2.3.0, < 2.3.3
>= 2.4.0, < 2.4.2
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
The TensorFlow package is an open-source machine learning framework developed by Google. It provides a comprehensive set of tools and libraries for building and deploying machine learning models. TensorFlow Lite (TFLite) is a lightweight version of TensorFlow designed for mobile and embedded devices. TFLite includes various operators, including the SpaceToDepth operator, which rearranges data spatially by dividing it into blocks and rearranging them. This vulnerability specifically affects the implementation of the SpaceToDepth operator in TFLite.
Vulnerability Detail
The vulnerability arises from a lack of validation in the Prepare step of the SpaceToDepth operator's implementation. The code does not check for a zero value before performing division operations, which can lead to a division by zero error. An attacker can exploit this vulnerability by crafting a malicious model that sets the block_size parameter to zero. This can cause the application to crash or behave unexpectedly. The impact of this vulnerability is considered low, as it requires the attacker to have control over the model being executed.
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 workaround, users can manually validate the block_size parameter before using it in the SpaceToDepth operator. By checking if the block_size is zero, the division operation can be avoided, preventing the division by zero error. Here is an example of how to implement the workaround in Python:
block_size = params['block_size']
if block_size != 0:
output_height = input_height // block_size
output_width = input_width // block_size
else:
# Handle the case when block_size is zero
output_height = 0
output_width = 0
Conclusion
In conclusion, the Division by zero vulnerability in TFLite's implementation of the SpaceToDepth operator can be exploited by crafting a malicious model with a zero block_size parameter. This can lead to application crashes or unexpected behavior. The vulnerability has been patched in TensorFlow and users are advised to update their installations to the patched versions once they are released. Regularly updating TensorFlow is recommended to ensure the latest security fixes are applied. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for tensorflow →
FAQ
TensorFlow is an open-source machine learning framework developed by Google. It provides a comprehensive set of tools and libraries for building and deploying machine learning models.
TensorFlow Lite (TFLite) is a lightweight version of TensorFlow designed for mobile and embedded devices. It includes various operators optimized for resource-constrained environments.
The SpaceToDepth operator is an operator in TensorFlow Lite that rearranges data spatially by dividing it into blocks and rearranging them. It is commonly used in computer vision tasks.
An attacker can exploit this vulnerability by crafting a malicious model that sets the block_size parameter of the SpaceToDepth operator to zero. This can cause the application to crash or behave unexpectedly.
The impact of this vulnerability is considered low, as it requires the attacker to have control over the model being executed. However, it can lead to application crashes or unexpected behavior.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.