CVE-2021-29556: Division by 0 in TensorFlow Reverse

tensorflow Updated 02 Oct 2025

Summary

21/05/2021
Yes i
Low
2.5

CVE-2021-29556: Division by 0 in Reverse. 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-29556 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 Devnack Mobile apps built by Devnack Design, build and launch iOS and Android apps with a senior product team. From idea to store release Start a project

Background

TensorFlow is an open-source machine learning framework widely used for developing and training various deep learning models. It provides a comprehensive set of tools and libraries for building and deploying machine learning applications. TensorFlow is available for multiple programming languages, including Python, and is known for its flexibility and scalability. However, a vulnerability has been discovered in the Reverse function of TensorFlow, which can lead to a denial of service attack.

Vulnerability Detail

The vulnerability, identified as CVE-2021-29556, exists in the Reverse function of TensorFlow. This function is used to reverse the order of elements along specified dimensions in a tensor. The implementation of this function performs a division based on the first dimension of the tensor argument. An attacker can exploit this vulnerability by providing a tensor with a first dimension of 0, causing a division by zero error. This error triggers a floating-point exception (FPE) runtime error, resulting in a denial of service. The impact of this vulnerability is limited to the availability of the affected TensorFlow application.

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 ensure that the tensor provided to the Reverse function has a non-zero first dimension. This can be achieved by checking the shape of the tensor before passing it to the function and handling the case where the first dimension is zero separately. Here is an example of how to implement this workaround in Python:

import tensorflow as tf

tensor_input = tf.constant([], shape=[0, 1, 1], dtype=tf.int32)
dims = tf.constant([False, True, False], shape=[3], dtype=tf.bool)

if tensor_input.shape[0] == 0:
    # Handle the case where the first dimension is zero
    # Perform necessary operations or raise an exception
else:
    tf.raw_ops.Reverse(tensor=tensor_input, dims=dims)

Conclusion

In conclusion, the Division by 0 vulnerability in TensorFlow's Reverse function can lead to a denial of service attack. Users are advised to update their TensorFlow installation to one of the patched versions to mitigate the risk. A workaround is also available by ensuring that the tensor provided to the Reverse function has a non-zero first dimension. For further support on vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for tensorflow →

Share this vulnerability

FAQ

The impact of this vulnerability is limited to the availability of the affected TensorFlow application. An attacker can trigger a denial of service by exploiting the vulnerability, causing the application to become unresponsive.

To fix this vulnerability, users should update their TensorFlow installation to one of the patched versions: TensorFlow 2.1.4, TensorFlow 2.2.3, TensorFlow 2.3.3, TensorFlow 2.4.2, or TensorFlow 2.5.0 (upcoming release). This can be done by upgrading the TensorFlow package using the package manager or by manually installing the updated version from the official TensorFlow repository.

Yes, a workaround is available for this vulnerability. Users can ensure that the tensor provided to the Reverse function has a non-zero first dimension. This can be achieved by checking the shape of the tensor before passing it to the function and handling the case where the first dimension is zero separately.

No, this vulnerability cannot be exploited remotely. An attacker needs to have access to the affected TensorFlow application to exploit the vulnerability and trigger a denial of service.

This vulnerability has been discovered by Ying Wang and Yakun Zhang of Baidu X-Team.

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.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