CVE-2021-37679: Heap OOB in nested `tf.map_fn` with `RaggedTensor`s in TensorFlow

tensorflow Updated 02 Oct 2025

Summary

25/08/2021
Yes i
High
7.1

CVE-2021-37679: Heap OOB in nested tf.map_fn with RaggedTensors. Affects tensorflow across 3 version ranges.

< 2.3.4 >= 2.4.0, < 2.4.3 >= 2.5.0, < 2.5.1

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

Also tracked for

The same CVE-2021-37679 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

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored MarkAI Find prospects already talking about the problem you solve AI watches the communities your customers use to find qualified prospects, then alerts you when a conversation is worth joining. See MarkAI

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 supports various data structures, including RaggedTensor, which allows for handling irregular and nested data. However, a vulnerability has been discovered in the nested usage of tf.map_fn with RaggedTensors, leading to a heap out-of-bounds (OOB) issue.

Vulnerability Detail

The vulnerability arises when nesting a tf.map_fn within another tf.map_fn call with a RaggedTensor as input. If no function signature is provided, the code assumes the output is a fully specified tensor and fills the output buffer with uninitialized contents from the heap. This can result in data leakage and potential memory information disclosure. The issue originates from the conversion from a Variant tensor to a RaggedTensor, where the implementation fails to check that all inner shapes match, leading to additional dimensions. The same vulnerability can also cause data loss if the input tensor is modified.

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.3.4 2.3.4
    pip install --upgrade "tensorflow==2.3.4"
  • >= 2.4.0, < 2.4.3 2.4.3
    pip install --upgrade "tensorflow==2.4.3"
  • >= 2.5.0, < 2.5.1 2.5.1
    pip install --upgrade "tensorflow==2.5.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 workaround, you can provide a function signature explicitly when using nested tf.map_fn with RaggedTensors. This ensures that the output tensor is correctly specified and avoids the uninitialized buffer issue. Here's an example:

import tensorflow as tf

x = tf.ragged.constant([[1,2,3], [4,5], [6]])

# Provide function signature
@tf.function
def map_fn_inner(y):
    return y

@tf.function
def map_fn_outer(r):
    return tf.map_fn(map_fn_inner, r)

t = tf.map_fn(map_fn_outer, x)

# t and z outputs should be identical
z = tf.ragged.constant([[[1,2,3],[1,2,3],[1,2,3]],[[4,5],[4,5]],[[6]]])

By explicitly defining the function signature, the issue of uninitialized buffer contents can be avoided.

Conclusion

The vulnerability in nested tf.map_fn with RaggedTensors in TensorFlow can lead to data leakage and potential memory information disclosure. It is crucial to update to the patched versions of TensorFlow (2.6.0, 2.5.1, 2.4.3, or 2.3.4) to mitigate this issue. By following the recommended steps for updating your TensorFlow installation, you can ensure the security and stability of your machine learning applications. 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 machine learning framework developed by Google. It provides a comprehensive ecosystem of tools, libraries, and resources for building and deploying machine learning models.

RaggedTensor is a data structure in TensorFlow that allows for handling irregular and nested data. It is particularly useful when dealing with sequences of varying lengths or nested structures.

The vulnerability occurs when nesting a tf.map_fn within another tf.map_fn call with a RaggedTensor as input. If no function signature is provided, the output buffer is filled with uninitialized contents from the heap, leading to data leakage and potential memory information disclosure.

The vulnerability can result in data leakage and potential memory information disclosure. It can also cause data loss if the input tensor is modified. An attacker could potentially exploit this vulnerability to access sensitive information or disrupt the functioning of TensorFlow applications.

To fix this vulnerability, it is recommended to update to the latest version of TensorFlow (2.6.0). If you are using an older version, consider upgrading to TensorFlow 2.5.1, TensorFlow 2.4.3, or TensorFlow 2.3.4. Follow the official TensorFlow documentation for instructions on how to update your installation.

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.3.4 2.3.4
    pip install --upgrade "tensorflow==2.3.4"
  • >= 2.4.0, < 2.4.3 2.4.3
    pip install --upgrade "tensorflow==2.4.3"
  • >= 2.5.0, < 2.5.1 2.5.1
    pip install --upgrade "tensorflow==2.5.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