CVE-2022-21740: TensorFlow Heap Overflow Vulnerability

tensorflow Updated 18 Jul 2026

Summary

09/07/2026
Yes i
High
7.6

CVE-2022-21740: Heap overflow in Tensorflow. Affects tensorflow across 3 version ranges.

< 2.5.3 >= 2.6.0, < 2.6.3 >= 2.7.0, < 2.7.1

Fixed in 2.5.3, 2.6.3 or 2.7.1, depending on the release line you run. How to fix ↓

Also tracked for

The same CVE-2022-21740 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 Your last release was probably never penetration tested 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 open-source machine learning library developed by Google, widely used for building and training machine learning models. It provides a flexible ecosystem of tools, libraries, and community resources that enables researchers and developers to create and deploy machine learning applications. However, it is susceptible to vulnerabilities that can compromise its functionality and security.

Vulnerability Detail

The vulnerability arises from a heap overflow in the implementation of the SparseCountSparseOutput function in TensorFlow. This flaw can be exploited when specific parameters are passed to the function, leading to potential memory corruption. The affected code can be triggered using the following Python snippet: import tensorflow as tf; tf.raw_ops.SparseCountSparseOutput(indices=[[-1,-1]], values=[2], dense_shape=[1, 1], weights=[1], binary_output=True, minlength=-1, maxlength=-1). If exploited, this vulnerability can lead to unauthorized access, data corruption, or application crashes.

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.5.3 2.5.3
    pip install --upgrade "tensorflow==2.5.3"
  • >= 2.6.0, < 2.6.3 2.6.3
    pip install --upgrade "tensorflow==2.6.3"
  • >= 2.7.0, < 2.7.1 2.7.1
    pip install --upgrade "tensorflow==2.7.1"

Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →

Workaround

Currently, there are no specific workarounds mentioned for this vulnerability. The best course of action is to update to the patched versions as soon as possible.

Conclusion

The heap overflow vulnerability in TensorFlow (CVE-2022-21740) poses significant risks to applications using the library. It is essential to update to the patched versions to ensure the security and stability of your machine learning applications. Regular monitoring for vulnerabilities using tools like Vulert can help maintain a secure environment.

See every vulnerability recorded for tensorflow →

Share this vulnerability

FAQ

CVE-2022-21740 is a vulnerability in TensorFlow that allows for a heap overflow, potentially leading to memory corruption and application instability.

You can use Vulert to monitor and alert for open-source vulnerabilities in your software. Visit the Vulert playground at Vulert Scanner to check if your application is affected without needing to sign up.

The affected versions of TensorFlow are all versions prior to 2.5.3, 2.6.3, and 2.7.1.

The CVSS score of this vulnerability is 7.6, indicating a high severity level.

While there are no specific workarounds, it is crucial to prioritize updating TensorFlow to the patched versions to mitigate the risk of exploitation.

Related vulnerabilities

Recent vulnerabilities recorded for tensorflow.

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.5.3 2.5.3
    pip install --upgrade "tensorflow==2.5.3"
  • >= 2.6.0, < 2.6.3 2.6.3
    pip install --upgrade "tensorflow==2.6.3"
  • >= 2.7.0, < 2.7.1 2.7.1
    pip install --upgrade "tensorflow==2.7.1"

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