CVE-2021-29541: Null pointer dereference in tensorflow
Summary
CVE-2021-29541: Null pointer dereference in StringNGrams. 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-29541 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 open-source machine learning framework developed by Google. It provides a comprehensive ecosystem of tools, libraries, and resources for building and deploying machine learning models. The vulnerability identified as CVE-2021-29541 affects the TensorFlow package, specifically the StringNGrams function. This function is responsible for generating n-grams from input strings. The vulnerability allows an attacker to trigger a null pointer dereference in the StringNGrams function, leading to a crash or potential code execution.
Vulnerability Detail
The vulnerability arises due to incomplete validation of the data_splits argument in the StringNGrams function. When the output size is computed to be zero or negative, the ngrams_data pointer becomes null. Subsequent writes to the output tensor can then cause a null pointer dereference. An attacker can exploit this vulnerability by providing specially crafted input data and data splits, leading to a crash or potential code execution. The impact of this 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
No specific workaround has been provided for this vulnerability.
Conclusion
The vulnerability CVE-2021-29541 in TensorFlow's StringNGrams function has been identified and patched. Users are advised to update their TensorFlow installation to the latest version once the fix is available. Regularly updating TensorFlow and other dependencies is recommended to ensure the application is protected against known vulnerabilities. For further support or assistance, you can contact the TensorFlow team at DevNack.com.
See every vulnerability recorded for tensorflow →
FAQ
TensorFlow is an open-source machine learning framework developed by Google. It provides a comprehensive ecosystem of tools, libraries, and resources for building and deploying machine learning models.
The impact of this vulnerability is considered low, with a CVSS score of 2.5. It can potentially lead to a crash or code execution.
To fix this vulnerability, update your TensorFlow installation to the latest version once the patch is available. Regularly updating TensorFlow and other dependencies is recommended for applying security patches.
No specific workaround has been provided for this vulnerability.
For further support on vulnerability remediation or any other TensorFlow-related issues, you can reach out to the TensorFlow team at info@devnack.com.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.