CVE-2022-21733: Memory Exhaustion in TensorFlow

tensorflow Updated 02 Oct 2025

Summary

10/02/2022
Yes i
Moderate
4.3

CVE-2022-21733: Memory exhaustion 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-21733 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 widely used for developing and training deep learning models. It provides a comprehensive ecosystem of tools, libraries, and resources for building and deploying machine learning applications. TensorFlow supports various platforms and is available for Python, C++, and other programming languages. However, a vulnerability has been discovered in TensorFlow that could lead to memory exhaustion.

Vulnerability Detail

The vulnerability in TensorFlow arises from an integer overflow in the implementation of the StringNGrams function. By providing specific input parameters, an attacker can trigger a denial of service (DoS) attack, causing an out-of-memory (OOM) condition. The issue occurs due to a lack of validation on the pad_width parameter, resulting in the computation of a negative value for ngram_width. This negative value is later used to allocate parts of the output, leading to memory exhaustion. An attacker can exploit this vulnerability to disrupt the availability of TensorFlow applications.

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 the vulnerability by ensuring that the pad_width parameter passed to the StringNGrams function is a non-negative value. By validating and sanitizing the input, the risk of triggering the memory exhaustion vulnerability can be mitigated. Here is an example of how to use the StringNGrams function with a validated pad_width parameter:

import tensorflow as tf

tf.raw_ops.StringNGrams(
  data=['123456'],
  data_splits=[0,1],
  separator='a'*15,
  ngram_widths=[],
  left_pad='',
  right_pad='',
  pad_width=max(0, -5), 
  preserve_short_sequences=True)

By using max(0, -5) as the pad_width value, the negative input will be converted to zero, preventing the vulnerability from being triggered.

Conclusion

The memory exhaustion vulnerability in TensorFlow can be mitigated by updating to the patched versions or by implementing the provided workaround. It is crucial for TensorFlow users to promptly address this vulnerability to ensure the security and availability of their machine learning applications. For further support and assistance in vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for tensorflow →

Share this vulnerability

FAQ

TensorFlow is an open-source machine learning framework used for developing and training deep learning models. It provides a comprehensive ecosystem of tools and resources for building machine learning applications.

The vulnerability in TensorFlow can be exploited to trigger a denial of service attack, causing memory exhaustion and disrupting the availability of TensorFlow applications.

To fix the vulnerability, update your TensorFlow installation to one of the patched versions: TensorFlow 2.5.3, TensorFlow 2.6.3, TensorFlow 2.7.1, or TensorFlow 2.8.0 (upcoming release).

Yes, as a temporary workaround, you can validate and sanitize the pad_width parameter passed to the StringNGrams function to ensure it is a non-negative value.

This vulnerability was reported by Yu Tian of Qihoo 360 AIVul Team.

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