CVE-2021-29605: TensorFlow TFLite Integer Overflow Vulnerability
Summary
CVE-2021-29605: 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.3
>= 2.4.0, < 2.4.2
< 7c8cc4ec69cd348e44ad6a2699057ca88faad3e5
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-29605 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 Lite (TFLite) is a lightweight version of TensorFlow designed for mobile and embedded devices. TFLite allows developers to run machine learning models on resource-constrained platforms. However, a vulnerability has been discovered in the TFLite code that handles the allocation of TFLiteIntArray objects.
Vulnerability Detail
The TFLite code for allocating TFLiteIntArrays is vulnerable to an integer overflow issue. This vulnerability arises due to an unchecked multiplication operation that can result in an overflow of the int datatype. An attacker can exploit this vulnerability by crafting a malicious model that triggers the overflow, leading to an invalid value being passed to the malloc function. As a result, the ret->size pointer dereferences an invalid memory location, potentially leading to a crash or arbitrary code execution. This vulnerability affects TensorFlow versions 2.1.4 and above, including TensorFlow 2.5.0.
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 temporary workaround, developers can manually apply the patch provided by the TensorFlow team to fix the integer overflow issue. The patch involves modifying the common.c file in the TFLite codebase. Here is the modified code snippet:
// Original code
int size = count * sizeof(int);
// Patched code
int64_t size64 = (int64_t)count * sizeof(int);
if (size64 > INT_MAX) {
// Handle the overflow case
// ... (allocate memory using a different approach)
} else {
int size = (int)size64;
// ... (allocate memory using the original approach)
}
Conclusion
In conclusion, a vulnerability has been identified in TensorFlow Lite (TFLite) that allows an attacker to trigger an integer overflow, potentially leading to crashes or arbitrary code execution. The TensorFlow team has released patches to address this vulnerability, and it is crucial for users to update their TensorFlow installations to the latest versions. For further assistance or support in 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 set of tools and libraries for building and deploying machine learning models.
TensorFlow Lite (TFLite) is a lightweight version of TensorFlow designed for running machine learning models on resource-constrained devices such as mobile phones and embedded systems.
The vulnerability occurs due to an unchecked multiplication operation in the TFLite code that can result in an overflow of the int datatype.
Exploiting this vulnerability can lead to crashes or arbitrary code execution, potentially allowing an attacker to gain unauthorized access or control over the affected system.
To fix this vulnerability, it is recommended to upgrade to the latest available version of TensorFlow (2.5.0 or above). Alternatively, you can apply the provided patch manually to mitigate the issue temporarily.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.