CVE-2021-37679: Heap OOB in nested `tf.map_fn` with `RaggedTensor`s in TensorFlow
Summary
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
- tensorflow · Bitnami
- tensorflow-cpu · PyPI
- tensorflow-gpu · PyPI
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.
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.
No signup required · Results in about 60 seconds
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.42.3.4pip install --upgrade "tensorflow==2.3.4" -
>= 2.4.0, < 2.4.32.4.3pip install --upgrade "tensorflow==2.4.3" -
>= 2.5.0, < 2.5.12.5.1pip 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 →
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.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.