CVE-2021-29593: TensorFlow - Division by Zero Error in BatchToSpaceNd Operator

tensorflow Updated 02 Oct 2025

Summary

06/03/2024
Yes i
High
Not published

CVE-2021-29593: Division by zero in TFLite's implementation of BatchToSpaceNd. 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-29593 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 end-to-end open source platform for machine learning. It provides a comprehensive ecosystem for building and deploying machine learning models. The BatchToSpaceNd operator in TensorFlow is used to rearrange data in a batched manner. It is vulnerable to a division by zero error when one dimension of the block input is set to 0, resulting in a corresponding value of 0 in the block_shape input. This vulnerability affects versions 0 and 2.1.4 to 2.4.2 of the TensorFlow package.

Vulnerability Detail

The vulnerability arises due to a lack of proper input validation in the BatchToSpaceNd operator implementation. An attacker can exploit this vulnerability by crafting a malicious model with a block input dimension set to 0, causing a division by zero error during execution. This can lead to various consequences, including denial of service (DoS) attacks, information disclosure, or even remote code execution. The vulnerability has been assigned a CVSSv3 severity score of 9.8 (Critical).

How To Fix

Fixed versions by release line

The minimum fixed version depends on the release line you run.

  • < 2.1.4 2.1.4
  • >= 2.2.0, < 2.2.3 2.2.3
  • >= 2.3.0, < 2.3.3 2.3.3
  • >= 2.4.0, < 2.4.2 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 manually validate the input dimensions before invoking the BatchToSpaceNd operator. By ensuring that none of the dimensions in the block input are set to 0, the division by zero error can be avoided. Here is an example of how to perform the input validation in Python:

import tensorflow as tf

def safe_batch_to_space_nd(input, block_shape, crops):
    for dim in block_shape:
        if dim == 0:
            raise ValueError('Invalid block shape: dimension cannot be 0')
    return tf.batch_to_space_nd(input, block_shape, crops)

Conclusion

The BatchToSpaceNd operator in TensorFlow is vulnerable to a division by zero error, which can have severe consequences such as DoS attacks, information disclosure, or remote code execution. It is crucial to upgrade to the latest version of TensorFlow (2.5.0 or later) to mitigate this vulnerability. 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 platform for machine learning, providing a comprehensive ecosystem for building and deploying machine learning models.

BatchToSpaceNd is an operator in TensorFlow used to rearrange data in a batched manner.

The vulnerability occurs due to a lack of input validation in the BatchToSpaceNd operator implementation, allowing a division by zero error when one dimension of the block input is set to 0.

The vulnerability can lead to denial of service (DoS) attacks, information disclosure, or remote code execution, depending on how it is exploited.

To fix this vulnerability, it is recommended to upgrade to the latest available version of TensorFlow (2.5.0 or later).

Related vulnerabilities

Recent vulnerabilities recorded for tensorflow.

How To Fix

Fixed versions by release line

The minimum fixed version depends on the release line you run.

  • < 2.1.4 2.1.4
  • >= 2.2.0, < 2.2.3 2.2.3
  • >= 2.3.0, < 2.3.3 2.3.3
  • >= 2.4.0, < 2.4.2 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