CVE-2021-37646: TensorFlow Integer Overflow in tf.raw_ops.StringNGrams

tensorflow-cpu Updated 02 Oct 2025

Summary

12/08/2021
Yes i
Unrated
Not published

CVE-2021-37646: TensorFlow is an end-to-end open source platform for machine learning. Affects tensorflow-cpu across 3 version ranges.

>= 2.3.0, < 2.3.4 >= 2.4.0, < 2.4.3 < c283e542a3f422420cfdb332414543b62fc4e4a5

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

Also tracked for

The same CVE-2021-37646 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 Mobile apps built by Devnack Design, build and launch iOS and Android apps with a senior product team. From idea to store release Start a project

Background

TensorFlow is an end-to-end open source platform for machine learning. It provides a comprehensive ecosystem of tools, libraries, and resources for developing and deploying machine learning models. TensorFlow is widely used in various domains, including computer vision, natural language processing, and deep learning. The vulnerability described in this report affects the TensorFlow package, specifically the implementation of tf.raw_ops.StringNGrams.

Vulnerability Detail

The vulnerability in TensorFlow arises from an integer overflow issue in the implementation of tf.raw_ops.StringNGrams. This vulnerability occurs when a signed integer value is converted to an unsigned one, leading to an allocation of memory based on this value. The vulnerable code can be found in the string_ngrams_op.cc file of the TensorFlow source code. The issue arises when the reserve method is called on a tstring with a value that can be negative if the user supplies negative ngram_widths. The reserve method internally calls TF_TString_Reserve, which expects an unsigned long argument for the size of the buffer. Due to the implicit conversion, the negative value is transformed into a large integer, causing an integer overflow. This vulnerability can be exploited by an attacker to trigger a buffer overflow or other memory-related issues, potentially leading to remote code execution or denial of service.

How To Fix

Latest published version: 2.21.0 as of 22 Oct 2026

pip install --upgrade "tensorflow-cpu==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.4 2.3.4
    pip install --upgrade "tensorflow-cpu==2.3.4"
  • >= 2.4.0, < 2.4.3 2.4.3
    pip install --upgrade "tensorflow-cpu==2.4.3"

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 known workaround for this vulnerability. It is recommended to apply the provided fix by updating TensorFlow to a patched version.

Conclusion

In conclusion, the vulnerability in TensorFlow's tf.raw_ops.StringNGrams function poses a risk of integer overflow, potentially leading to memory-related issues and remote code execution. The TensorFlow development team has addressed this vulnerability in the latest versions of TensorFlow and has provided patches for older affected versions. Users are strongly advised to update their TensorFlow installations to the patched versions to mitigate the risk. For further support on vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for tensorflow-cpu →

Share this vulnerability

FAQ

TensorFlow is an open source platform for machine learning that provides a comprehensive ecosystem of tools and resources for developing and deploying machine learning models.

This vulnerability in TensorFlow can potentially lead to remote code execution or denial of service if exploited by an attacker.

The vulnerability affects TensorFlow versions 2.3.0 and above. Specifically, TensorFlow 2.3.4, TensorFlow 2.4.3, and TensorFlow 2.5.1 are known to be affected.

Yes, the TensorFlow development team has released patches for this vulnerability. Users are advised to update their TensorFlow installation to one of the patched versions.

No, there are no known workarounds for this vulnerability. It is recommended to apply the provided fix by updating TensorFlow to a patched version.

Related vulnerabilities

Recent vulnerabilities recorded for tensorflow-cpu.

How To Fix

Latest published version: 2.21.0 as of 22 Oct 2026

pip install --upgrade "tensorflow-cpu==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.4 2.3.4
    pip install --upgrade "tensorflow-cpu==2.3.4"
  • >= 2.4.0, < 2.4.3 2.4.3
    pip install --upgrade "tensorflow-cpu==2.4.3"

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