CVE-2021-29608: Heap OOB and null pointer dereference in tensorflow

tensorflow Updated 02 Oct 2025

Summary

21/05/2021
Yes i
Moderate
5.3

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

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.

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 Lume, the Habilume companion Habilume Habit tracker with a companion that grows with you Complete habits, earn Lume Points, and watch your Lume grow as you stay consistent. App Store Google Play

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.4 2.1.4
    pip install --upgrade "tensorflow==2.1.4"
  • >= 2.2.0, < 2.2.3 2.2.3
    pip install --upgrade "tensorflow==2.2.3"
  • >= 2.3.0, < 2.3.3 2.3.3
    pip install --upgrade "tensorflow==2.3.3"
  • >= 2.4.0, < 2.4.2 2.4.2
    pip 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 →

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.

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.

Related vulnerabilities

Recent vulnerabilities recorded for tensorflow.

Sponsored Lume, the Habilume companion Habilume Habit tracker with a companion that grows with you Complete habits, earn Lume Points, and watch your Lume grow as you stay consistent. App Store Google Play

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.4 2.1.4
    pip install --upgrade "tensorflow==2.1.4"
  • >= 2.2.0, < 2.2.3 2.2.3
    pip install --upgrade "tensorflow==2.2.3"
  • >= 2.3.0, < 2.3.3 2.3.3
    pip install --upgrade "tensorflow==2.3.3"
  • >= 2.4.0, < 2.4.2 2.4.2
    pip 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 →

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