CVE-2021-29536: Heap buffer overflow in tensorflow

tensorflow Updated 02 Oct 2025

Summary

21/05/2021
Yes i
Low
2.5

CVE-2021-29536: Heap buffer overflow in QuantizedReshape. 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-29536 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 community resources that enable researchers and developers to build and deploy machine learning models. TensorFlow is widely used in various domains, including computer vision, natural language processing, and reinforcement learning. However, a vulnerability has been discovered in TensorFlow that could lead to a heap buffer overflow.

Vulnerability Detail

The vulnerability, identified as CVE-2021-29536, exists in the QuantizedReshape function of TensorFlow. It can be exploited by an attacker by passing invalid thresholds for quantization. This can be achieved by providing empty tensors for the tensor, shape, input_min, and input_max parameters. The implementation of QuantizedReshape assumes that these arguments are always valid scalars and attempts to access their numeric values directly. However, if any of these tensors is empty, accessing the element at position 0 results in a heap buffer overflow. This vulnerability can potentially allow an attacker to execute arbitrary code or cause a denial-of-service condition.

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 temporary workaround, users can ensure that the tensors passed to the QuantizedReshape function are not empty. This can be achieved by validating the input tensors before invoking the function. Here is an example of how to perform this validation in Python:

import tensorflow as tf

tensor = tf.constant([], dtype=tf.qint32)
shape = tf.constant([], dtype=tf.int32)
input_min = tf.constant([], dtype=tf.float32)
input_max = tf.constant([], dtype=tf.float32)

if tensor.shape.num_elements() == 0 or shape.shape.num_elements() == 0 or input_min.shape.num_elements() == 0 or input_max.shape.num_elements() == 0:
    # Handle the empty tensors
    print('Invalid input tensors')
else:
    tf.raw_ops.QuantizedReshape(tensor=tensor, shape=shape, input_min=input_min, input_max=input_max)

By performing this validation, the vulnerability can be mitigated by preventing the execution of the vulnerable code path when empty tensors are encountered.

Conclusion

The vulnerability in TensorFlow can be mitigated by updating to the patched versions or by implementing the provided workaround. It is important for users to stay vigilant and apply the necessary updates to ensure the security of their TensorFlow installations. 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 libraries for building and deploying machine learning models.

The vulnerability allows an attacker to cause a heap buffer overflow in TensorFlow, potentially leading to arbitrary code execution or a denial-of-service condition.

The vulnerability has been patched in TensorFlow commit a324ac84e573fba362a5e53d4e74d5de6729933e. Users should update their TensorFlow installations to the patched versions once they become available.

No, the vulnerability affects TensorFlow versions 2.1.4 and above. Earlier versions are not affected.

Yes, users can validate the input tensors before invoking the vulnerable function to prevent the execution of the vulnerable code path when empty tensors are encountered.

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