CVE-2021-29585: Division by zero in padding computation in TFLite
Summary
CVE-2021-29585: Division by zero in padding computation in TFLite. 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-29585 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 Lite (TFLite) package is an open-source machine learning framework developed by TensorFlow. It is designed to run on resource-constrained devices, such as mobile and embedded devices, and provides efficient execution of machine learning models. TFLite includes various operations and functions for model inference, including padding computation for image processing. However, a vulnerability has been identified in the padding computation function of TFLite, which can lead to a division by zero error.
Vulnerability Detail
The vulnerability in TFLite arises from the ComputeOutSize function, which calculates the size of the output after padding. This function does not check whether the stride argument is zero before performing the division. As a result, if a user crafts a model that calls ComputeOutSize with a stride value of zero, a division by zero error will occur. This vulnerability can be exploited by an attacker to cause a denial-of-service condition or potentially execute arbitrary code. The impact of the vulnerability is considered low, with a CVSS score of 2.5.
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 check the stride argument before calling the ComputeOutSize function to ensure it is not zero. If the stride value is zero, an alternative calculation or padding method should be used to avoid the division by zero error. Here is an example of how to perform the check in Python:
def compute_out_size(padding, image_size, filter_size, stride, dilation_rate=1):
effective_filter_size = (filter_size - 1) * dilation_rate + 1
if stride == 0:
# Handle the case where stride is zero
return 0
elif padding == 'SAME':
return (image_size + stride - 1) // stride
elif padding == 'VALID':
return (image_size + stride - effective_filter_size) // stride
else:
return 0
By explicitly checking the stride value, the division by zero error can be avoided.
Conclusion
In conclusion, the vulnerability in TFLite's padding computation function can result in a division by zero error. While the impact is considered low, it is important to update to the patched versions of TensorFlow once they are released. Users can also manually check the stride argument or use the provided workaround to mitigate the vulnerability. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for tensorflow →
FAQ
TensorFlow Lite (TFLite) is an open-source machine learning framework developed by TensorFlow. It is designed for running machine learning models on resource-constrained devices, such as mobile and embedded devices.
The impact of this vulnerability is considered low, with a CVSS score of 2.5. It can potentially lead to a denial-of-service condition or allow an attacker to execute arbitrary code.
To fix this vulnerability, users should update their TensorFlow installation to the patched versions once they are released. The fix will be included in TensorFlow 2.5.0 and backported to versions 2.4.2, 2.3.3, 2.2.3, and 2.1.4.
Yes, as a workaround, users can manually check the stride argument before calling the ComputeOutSize function to ensure it is not zero. If the stride value is zero, an alternative calculation or padding method should be used to avoid the division by zero error.
This vulnerability was reported by members of the Aivul Team from Qihoo 360.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.