CVE-2021-29608: Heap OOB and null pointer dereference in tensorflow
Summary
CVE-2021-29608: Heap OOB and null pointer dereference in RaggedTensorToTensor. Affects tensorflow across 4 version ranges.
< 2.1.4
>= 2.2.0, < 2.2.3
>= 2.3.0, < 2.3.3
>= 2.4.0, < 2.4.2
Fixed in 4 releases; the minimum fixed version depends on the release line you run. How to fix ↓
Also tracked for
- tensorflow · Bitnami
- tensorflow-cpu · PyPI
- tensorflow-gpu · PyPI
The same CVE-2021-29608 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 represents ragged or sparse tensors. The vulnerability identified in TensorFlow is related to the RaggedTensorToTensor function, which converts a RaggedTensor to a dense tensor. This function lacks proper validation, leading to a heap out-of-bounds (OOB) read and a null pointer dereference.
Vulnerability Detail
The vulnerability arises from the absence of validation in the tf.raw_ops.RaggedTensorToTensor function. If the input arguments are empty, the function triggers undefined behavior. An attacker can exploit this behavior by providing empty input arguments, leading to a heap OOB and null pointer dereference. The implementation of the function only checks if one of the tensors is not empty, but fails to validate the others. Although there are DCHECK validations to prevent heap OOB, they are ineffective in release builds. The impact of this vulnerability can result in a denial-of-service (DoS) scenario or potential information disclosure.
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.1.42.1.4pip install --upgrade "tensorflow==2.1.4" -
>= 2.2.0, < 2.2.32.2.3pip install --upgrade "tensorflow==2.2.3" -
>= 2.3.0, < 2.3.32.3.3pip install --upgrade "tensorflow==2.3.3" -
>= 2.4.0, < 2.4.22.4.2pip install --upgrade "tensorflow==2.4.2"
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, users can validate the input arguments before calling the RaggedTensorToTensor function. By ensuring that at least one of the tensors is not empty, the vulnerability can be mitigated. Here is an example of how to perform the validation:
import tensorflow as tf
shape = tf.constant([-1, -1], shape=[2], dtype=tf.int64)
values = tf.constant([], shape=[0], dtype=tf.int64)
default_value = tf.constant(404, dtype=tf.int64)
row = tf.constant([269, 404, 0, 0, 0, 0, 0], shape=[7], dtype=tf.int64)
rows = [row]
types = ['ROW_SPLITS']
if any(t.shape.num_elements() == 0 for t in rows):
print('Invalid input: Empty tensor found.')
else:
tf.raw_ops.RaggedTensorToTensor(
shape=shape, values=values, default_value=default_value,
row_partition_tensors=rows, row_partition_types=types)
By checking if any of the tensors in rows have zero elements, the vulnerability can be avoided.
Conclusion
The vulnerability in TensorFlow (CVE-2021-29608) allows for a heap OOB read and null pointer dereference in the RaggedTensorToTensor function. It can be exploited by providing empty input arguments, potentially leading to a DoS scenario or information disclosure. Users should update their TensorFlow installation to the latest patched version or apply the backported fixes for affected versions. Regularly updating TensorFlow is recommended to ensure the latest security fixes are in place. 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 tools and resources for building and deploying machine learning models.
RaggedTensorToTensor is a function in TensorFlow that converts a RaggedTensor to a dense tensor.
A RaggedTensor is a data structure in TensorFlow that represents ragged or sparse tensors.
A heap OOB read occurs when a program accesses memory outside the bounds of a heap-allocated object.
A null pointer dereference occurs when a program attempts to access or manipulate memory through a null pointer.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.