CVE-2021-29521: TensorFlow - Segmentation Fault in SparseCountSparseOutput
Summary
CVE-2021-29521: TensorFlow is an end-to-end open source platform for machine learning. Affects tensorflow across 3 version ranges.
>= 2.3.0, < 2.3.3
>= 2.4.0, < 2.4.2
< c57c0b9f3a4f8684f3489dd9a9ec627ad8b599f5
Fixed in 2.3.3 or 2.4.2, 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-29521 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 resources for building and deploying machine learning models. TensorFlow is widely used in various domains, including research, industry, and academia. It offers support for both deep learning and traditional machine learning algorithms, making it a popular choice among developers and data scientists.
Vulnerability Detail
The vulnerability (CVE-2021-29521) in TensorFlow arises when specifying a negative dense shape in the tf.raw_ops.SparseCountSparseOutput function. This leads to a segmentation fault being thrown from the standard library due to broken std::vector invariants. The issue originates from the assumption made in the implementation that the first element of the dense shape is always positive. This assumption is used to initialize a BatchedMap<T> data structure, which is a std::vector<absl::flat_hash_map<int64,T>>. If the shape tensor has more than one element, num_batches is considered as the first value in shape. To mitigate this vulnerability, it is necessary to ensure that the dense_shape argument is a valid tensor shape with all non-negative elements.
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.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
There is no specific workaround mentioned for this vulnerability.
Conclusion
The vulnerability in TensorFlow (CVE-2021-29521) can lead to a segmentation fault when specifying a negative dense shape. It is important to ensure that the dense_shape argument is a valid tensor shape with all non-negative elements. The fix for this vulnerability will be included in TensorFlow 2.5.0, and you can also apply the fix by cherrypicking the commit for TensorFlow 2.4.2 and 2.3.3. For further support on vulnerability remediation, you can reach out to DevNack.com.
See every vulnerability recorded for tensorflow →
FAQ
TensorFlow is an open source platform for machine learning that provides tools and resources for building and deploying machine learning models.
The vulnerability can result in a segmentation fault, leading to a crash or instability in applications using TensorFlow.
The vulnerability affects TensorFlow versions 2.3.0 to 2.3.3 and 2.4.0 to 2.4.2.
You can fix this vulnerability by updating to TensorFlow 2.5.0 once it is released or by cherrypicking the fix commit from the TensorFlow GitHub repository for versions 2.4.2 and 2.3.3.
No specific workaround has been mentioned for this vulnerability.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.