CVE-2021-41215: Null Pointer Exception in TensorFlow

tensorflow Updated 02 Oct 2025

Summary

10/11/2021
Yes i
Moderate
5.5

CVE-2021-41215: Null pointer exception in DeserializeSparse. Affects tensorflow across 3 version ranges.

< 2.4.4 >= 2.5.0, < 2.5.2 >= 2.6.0, < 2.6.1

Fixed in 2.4.4, 2.5.2 or 2.6.1, depending on the release line you run. How to fix ↓

Also tracked for

The same CVE-2021-41215 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 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 platforms and is widely used in both research and production environments. However, a vulnerability has been identified in TensorFlow that can lead to a null pointer exception.

Vulnerability Detail

The vulnerability, identified as CVE-2021-41215, originates from a null pointer dereference in the DeserializeSparse function of TensorFlow. This vulnerability can be triggered when the shape inference code assumes that the serialize_sparse tensor has a positive rank and a specific last dimension. However, if the argument passed to the function is a scalar (rank 0), a null pointer exception occurs. This vulnerability can potentially be exploited by an attacker to cause a denial of service or execute arbitrary code.

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.4.4 2.4.4
    pip install --upgrade "tensorflow==2.4.4"
  • >= 2.5.0, < 2.5.2 2.5.2
    pip install --upgrade "tensorflow==2.5.2"
  • >= 2.6.0, < 2.6.1 2.6.1
    pip install --upgrade "tensorflow==2.6.1"

Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →

Workaround

If updating TensorFlow is not immediately possible, a workaround for this vulnerability is to ensure that the serialize_sparse tensor passed to the DeserializeSparse function has a positive rank and a valid last dimension. This can be achieved by reshaping the tensor or providing a tensor with the expected shape. Here is an example workaround in Python:

import tensorflow as tf

dataset = tf.data.Dataset.range(3)

@tf.function
def test():
  serialized_sparse = tf.data.experimental.to_variant(dataset)
  reshaped_sparse = tf.reshape(serialized_sparse, [1])
  y = tf.raw_ops.DeserializeSparse(reshaped_sparse, dtype=tf.int32)

test()

Conclusion

The vulnerability CVE-2021-41215 in TensorFlow has been addressed by the TensorFlow team in versions 2.6.1, 2.5.2, and 2.4.4. Users are advised to update their TensorFlow installation to one of the patched versions to mitigate the risk of exploitation. It is recommended to always stay up to date with the latest stable version of TensorFlow for improved security. 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 tools and resources for building and deploying machine learning models.

The vulnerability can lead to a null pointer exception, potentially causing a denial of service or arbitrary code execution.

The vulnerability affects TensorFlow versions 2.4.4, 2.5.2, and 2.6.0.

To fix the vulnerability, update your TensorFlow installation to one of the patched versions: TensorFlow 2.6.1, TensorFlow 2.5.2, or TensorFlow 2.4.4.

Yes, a workaround is to ensure that the serialize_sparse tensor passed to the DeserializeSparse function has a positive rank and a valid last dimension.

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.4.4 2.4.4
    pip install --upgrade "tensorflow==2.4.4"
  • >= 2.5.0, < 2.5.2 2.5.2
    pip install --upgrade "tensorflow==2.5.2"
  • >= 2.6.0, < 2.6.1 2.6.1
    pip install --upgrade "tensorflow==2.6.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