CVE-2021-29521: TensorFlow - Negative Dense Shape in SparseCountSparseOutput Leads to Segmentation Fault

tensorflow Updated 02 Oct 2025

Summary

06/03/2024
Yes i
Medium
Not published

CVE-2021-29521: Segfault in SparseCountSparseOutput. Affects tensorflow across 2 version ranges.

>= 2.3.0, < 2.3.3 >= 2.4.0, < 2.4.2

Fixed in 2.3.3 or 2.4.2, depending on the release line you run. How to fix ↓

Also tracked for

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.

Free scan

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.

Check my app free

No signup required · Results in about 60 seconds

Sponsored Devnack Penetration testing for web, API and mobile Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

TensorFlow is an end-to-end open source platform for machine learning. It provides a comprehensive ecosystem for building and deploying machine learning models. TensorFlow is widely used in various industries and research domains due to its flexibility, scalability, and extensive library of pre-built models and tools. However, a vulnerability has been identified in TensorFlow that can lead to a segmentation fault when specifying a negative dense shape in the tf.raw_ops.SparseCountSparseOutput function.

Vulnerability Detail

The vulnerability arises from a flaw in the implementation of the tf.raw_ops.SparseCountSparseOutput function. When a negative dense shape is provided, the implementation assumes 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 vector of absl::flat_hash_map<int64,T>. However, if the shape tensor has more than one element, num_batches is the first value in shape. As a result, the implementation breaks the invariants of the std::vector and throws a segmentation fault. An attacker could potentially exploit this vulnerability to cause a denial of service or execute arbitrary code.

How To Fix

Fixed versions by release line

The minimum fixed version depends on the release line you run.

  • >= 2.3.0, < 2.3.3 2.3.3
  • >= 2.4.0, < 2.4.2 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 provided for this vulnerability. The recommended approach is to apply the fix by upgrading to the patched versions of TensorFlow.

Conclusion

The vulnerability in TensorFlow that allows a segmentation fault when specifying a negative dense shape in tf.raw_ops.SparseCountSparseOutput has been identified and fixed in TensorFlow 2.5.0. It is recommended to upgrade to the patched versions of TensorFlow to mitigate the risk of exploitation. For further support on vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for tensorflow →

Share this vulnerability

FAQ

TensorFlow is an open source platform for machine learning that provides a comprehensive ecosystem for building and deploying machine learning models.

The vulnerability can lead to a segmentation fault, potentially causing a denial of service or enabling arbitrary code execution.

To fix this vulnerability, upgrade to TensorFlow 2.5.0 or apply the fix by upgrading to TensorFlow 2.4.2 or TensorFlow 2.3.3.

There is no specific workaround provided. It is recommended to apply the fix by upgrading to the patched versions of TensorFlow.

You can find more information about this vulnerability in the official TensorFlow documentation and the CVE entry.

Related vulnerabilities

Recent vulnerabilities recorded for tensorflow.

How To Fix

Fixed versions by release line

The minimum fixed version depends on the release line you run.

  • >= 2.3.0, < 2.3.3 2.3.3
  • >= 2.4.0, < 2.4.2 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 →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback