CVE-2021-41210: Heap OOB read in tensorflow
Summary
CVE-2021-41210: Heap OOB read in tf.raw_ops.SparseCountSparseOutput. Affects tensorflow across 3 version ranges.
< 2.4.4
>= 2.5.0, < 2.5.2
>= 2.6.0, < 2.6.1
Fixed in 2.4.4, 2.5.2 or 2.6.1, depending on the release line you run. How to fix ↓
Also tracked for
- tensorflow · Bitnami
- tensorflow-cpu · PyPI
- tensorflow-gpu · PyPI
The same CVE-2021-41210 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. TensorFlow is widely used in various domains, including research, industry, and academia. However, a vulnerability has been identified in TensorFlow that could potentially lead to a heap out-of-bounds read.
Vulnerability Detail
The vulnerability, identified as CVE-2021-41210, exists in the tf.raw_ops.SparseCountSparseOutput function of TensorFlow. This function is responsible for shape inference in sparse count operations. The issue arises when the function fails to check the rank of the input indices parameter, which should have a rank of 2. As a result, a read operation can occur outside the bounds of the heap-allocated array. An attacker could potentially exploit this vulnerability to read sensitive information or cause a denial-of-service condition.
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.4.42.4.4pip install --upgrade "tensorflow==2.4.4" -
>= 2.5.0, < 2.5.22.5.2pip install --upgrade "tensorflow==2.5.2" -
>= 2.6.0, < 2.6.12.6.1pip install --upgrade "tensorflow==2.6.1"
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 avoid using the tf.raw_ops.SparseCountSparseOutput function with inputs that do not have a rank of 2. It is recommended to review the code and ensure that the indices parameter is correctly shaped before passing it to the function. Here is an example of how to check the rank of the indices tensor in Python:
import tensorflow as tf
indices = tf.constant([[1, 2], [3, 4]])
rank = tf.rank(indices)
if rank != 2:
print('Error: indices tensor should have rank 2')
Conclusion
The vulnerability identified as CVE-2021-41210 in TensorFlow can lead to a heap out-of-bounds read. It is crucial to update your TensorFlow installation to one of the patched versions to mitigate the risk. Additionally, ensure that the indices parameter passed to the tf.raw_ops.SparseCountSparseOutput function has a rank of 2. For further support and assistance in 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 tools and resources for building and deploying machine learning models.
The vulnerability can lead to a heap out-of-bounds read, potentially allowing an attacker to read sensitive information or cause a denial-of-service condition.
To fix the vulnerability, update your TensorFlow installation to one of the patched versions: TensorFlow 2.7.0, TensorFlow 2.6.1, TensorFlow 2.5.2, or TensorFlow 2.4.4.
As a temporary workaround, ensure that the indices parameter passed to the tf.raw_ops.SparseCountSparseOutput function has a rank of 2.
For more information regarding TensorFlow security and how to report issues, please consult the TensorFlow security guide.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.