CVE-2021-29595: TensorFlow - Division by Zero in DepthToSpace TFLite Operator

tensorflow Updated 02 Oct 2025

Summary

06/03/2024
Yes i
High
Not published

CVE-2021-29595: Division by zero in TFLite's implementation of DepthToSpace. 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-29595 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 Penetration testing for web, API and mobile Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

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 DepthToSpace TFLite operator is a part of TensorFlow and is used for rearranging data in a tensor. This operator is vulnerable to a division by zero error, which can be exploited by an attacker. The vulnerability exists in the implementation of the operator, specifically in the depth_to_space.cc file. The affected versions of TensorFlow include 2.1.4, 2.2.3, 2.3.3, and 2.4.2.

Vulnerability Detail

The vulnerability in the DepthToSpace TFLite operator arises from a division by zero error. An attacker can craft a malicious model in which the params->block_size parameter is set to 0. When this model is executed, the division operation in the operator's implementation will result in a division by zero error. This can lead to various consequences, including crashes, denial of service, or even potential remote code execution. The issue has been identified and a fix will be included in TensorFlow 2.5.0. Additionally, the fix will be backported to TensorFlow 2.4.2, 2.3.3, 2.2.3, and 2.1.4 to address the vulnerability in the supported versions.

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 avoid the vulnerability by ensuring that the params->block_size parameter in the DepthToSpace TFLite operator is never set to 0. This can be achieved by validating and sanitizing the input values before executing the model. Here is an example code snippet that demonstrates the workaround:

import tensorflow as tf

# Validate and sanitize the block_size parameter
block_size = get_block_size()
if block_size == 0:
    block_size = 1

# Create and execute the model
model = create_model()
output = model.predict(block_size=block_size)

Conclusion

In conclusion, the DepthToSpace TFLite operator in TensorFlow is vulnerable to a division by zero error. This can be exploited by an attacker by crafting a malicious model. The issue has been identified and a fix will be included in TensorFlow 2.5.0. Users of the affected versions can expect the fix to be backported and included in the respective patch releases. It is recommended to update TensorFlow to the latest version once the fix is available. 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 that provides a comprehensive ecosystem for building and deploying machine learning models.

The DepthToSpace TFLite operator is a part of TensorFlow and is used for rearranging data in a tensor.

The vulnerability can lead to various consequences, including crashes, denial of service, or potential remote code execution.

The vulnerability affects TensorFlow versions 2.1.4, 2.2.3, 2.3.3, and 2.4.2.

To fix the vulnerability, it is recommended to update TensorFlow to version 2.5.0 once it is released. For users of the affected versions, the fix will be backported and included in the respective patch releases.

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