CVE-2022-21740: Heap overflow in Tensorflow

tensorflow Updated 02 Oct 2025

Summary

09/02/2022
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 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 discovered in Tensorflow that could lead to a heap overflow.

Vulnerability Detail

The implementation of SparseCountSparseOutput in Tensorflow is vulnerable to a heap overflow. This vulnerability can be triggered by providing malicious input to the indices, values, dense_shape, weights, binary_output, minlength, or maxlength parameters. An attacker could exploit this vulnerability to execute arbitrary code, cause a denial of service, or gain unauthorized access to sensitive information. The vulnerability has been assigned a CVSS score of 7.6, indicating a high severity level.

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

As a temporary workaround, users can avoid using the SparseCountSparseOutput function or ensure that the input provided to the function is valid and does not trigger the vulnerability. Here is an example of how to use the function safely:

import tensorflow as tf
import numpy as np

tf.raw_ops.SparseCountSparseOutput(
  indices=[[0, 0]],
  values=[2],
  dense_shape=[1, 1],
  weights=[1],
  binary_output=True,
  minlength=0,
  maxlength=0,
  name=None)

By providing valid input values and avoiding negative or large values for minlength and maxlength, the vulnerability can be mitigated.

Conclusion

In conclusion, the vulnerability in Tensorflow could lead to a heap overflow, allowing an attacker to execute arbitrary code, cause a denial of service, or gain unauthorized access to sensitive information. It is crucial for users to update their Tensorflow installation to one of the patched versions (2.5.3, 2.6.3, 2.7.1, or 2.8.0) to mitigate the vulnerability. For further support and assistance with vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for tensorflow →

Share this vulnerability

FAQ

The vulnerability could allow an attacker to execute arbitrary code, cause a denial of service, or gain unauthorized access to sensitive information.

The vulnerability affects Tensorflow versions 0 to 2.5.2, 2.6.0 to 2.6.2, and 2.7.0 to 2.7.0.

Yes, the vulnerability has been patched in Tensorflow versions 2.5.3, 2.6.3, 2.7.1, and 2.8.0.

To update your Tensorflow installation, you can use the package manager command specific to your operating system or manually download and install the updated version from the official Tensorflow website.

Yes, as a temporary workaround, you can avoid using the SparseCountSparseOutput function or ensure that the input provided to the function is valid and does not trigger the vulnerability.

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