CVE-2021-29516: TensorFlow - Null Pointer Dereference in RaggedTensorToVariant
Summary
CVE-2021-29516: TensorFlow is an end-to-end open source platform for machine learning. Affects tensorflow across 5 version ranges.
< 2.1.4
>= 2.2.0, < 2.2.3
>= 2.3.0, < 2.3.3
>= 2.4.0, < 2.4.2
< b055b9c474cd376259dde8779908f9eeaf097d93
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-29516 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 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 allows users to build and train neural networks, perform data preprocessing and augmentation, and deploy models in various environments. It is widely used in both research and production settings.
Vulnerability Detail
The vulnerability (CVE-2021-29516) in TensorFlow arises from a null pointer dereference in the tf.raw_ops.RaggedTensorToVariant function. When this function is called with arguments specifying an invalid ragged tensor, it can result in a null pointer dereference. The issue lies in the implementation of the RaggedTensorToVariant operations, which fails to validate that the ragged tensor argument is non-empty. As a result, if the batched_ragged tensor contains no elements, the batched_ragged.splits(0) operation will dereference a null pointer. This vulnerability can lead to crashes or other unexpected behavior in applications that utilize TensorFlow's ragged tensor functionality.
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 ragged tensor argument before calling the tf.raw_ops.RaggedTensorToVariant function. By checking if the ragged tensor is non-empty, the null pointer dereference can be avoided. Here's an example of how to perform the validation in Python:
import tensorflow as tf
def safe_ragged_tensor_to_variant(ragged_tensor):
if ragged_tensor.shape.num_elements() == 0:
return None
else:
return tf.raw_ops.RaggedTensorToVariant(ragged_tensor)
Conclusion
The null pointer dereference vulnerability in TensorFlow (CVE-2021-29516) can lead to crashes or unexpected behavior in applications that use ragged tensors. It is important to update TensorFlow to the fixed versions or the latest version to mitigate the risk. Regularly checking for updates and applying them promptly is recommended. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for tensorflow →
FAQ
TensorFlow is an open source platform for machine learning that provides a comprehensive set of tools and resources for developing and deploying machine learning models.
A ragged tensor is a type of tensor in TensorFlow that can represent sequences with variable lengths. It is commonly used in natural language processing tasks where the length of sentences or documents may vary.
The vulnerability occurs when the tf.raw_ops.RaggedTensorToVariant function is called with arguments specifying an invalid ragged tensor. If the ragged tensor is empty, the function fails to validate it, leading to a null pointer dereference.
The null pointer dereference vulnerability in TensorFlow can result in crashes or other unexpected behavior in applications that use ragged tensors. This can lead to application instability, data corruption, or even potential security risks if the vulnerability is exploited.
To protect your applications, it is recommended to update TensorFlow to the latest version (2.5.0) or the fixed versions (2.4.2, 2.3.3, 2.2.3, or 2.1.4). Regularly checking for updates and applying them promptly is crucial to ensure the security and stability of your TensorFlow-based applications.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.