CVE-2021-29587: TensorFlow CPU - SpaceToDepth TFLite Operator Division by Zero

tensorflow-cpu Updated 02 Oct 2025

Summary

14/05/2021
Yes i
Unrated
Not published

CVE-2021-29587: TensorFlow is an end-to-end open source platform for machine learning. Affects tensorflow-cpu across 5 version ranges.

< 0d45ea1ca641b21b73bcf9c00e0179cda284e7e7 >= 2.2.0, < 2.3.0rc0 < 2.2.0rc0 >= 2.3.0, < 2.3.4 >= 2.4.0, < 2.4.3

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-29587 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 of tools, libraries, and community resources that enable researchers and developers to build and deploy machine learning models. TensorFlow includes the SpaceToDepth TFLite operator, which is used for rearranging data in a tensor. This operator is vulnerable to a division by zero issue in the Prepare step, where it fails to check for a zero value before performing division. This vulnerability can be exploited by an attacker by crafting a malicious model that sets the block_size parameter to zero. The issue has been identified in TensorFlow versions 2.1.4 to 2.4.3, as well as in the tensorflow-cpu package on PyPI.

Vulnerability Detail

The vulnerability in the SpaceToDepth TFLite operator allows an attacker to trigger a division by zero error by providing a crafted model with a block_size parameter set to zero. This can lead to a crash or undefined behavior in the TensorFlow runtime. The impact of this vulnerability depends on the context in which TensorFlow is used. In some scenarios, it may allow an attacker to cause a denial of service (DoS) by crashing the application or potentially execute arbitrary code.

How To Fix

Latest published version: 2.21.0 as of 22 Oct 2026

pip install --upgrade "tensorflow-cpu==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.2.0rc0 2.2.0rc0
    pip install --upgrade "tensorflow-cpu==2.2.0rc0"
  • >= 2.2.0, < 2.3.0rc0 2.3.0rc0
    pip install --upgrade "tensorflow-cpu==2.3.0rc0"
  • >= 2.3.0, < 2.3.4 2.3.4
    pip install --upgrade "tensorflow-cpu==2.3.4"
  • >= 2.4.0, < 2.4.3 2.4.3
    pip install --upgrade "tensorflow-cpu==2.4.3"

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 check the value of the block_size parameter before passing it to the SpaceToDepth TFLite operator. This can be done by adding a conditional check in the code that sets the block_size value, ensuring it is not zero. Here is an example of how to perform the check in Python:

block_size = ...  # Set the block size

if block_size != 0:
    # Call the SpaceToDepth TFLite operator
    ...
else:
    # Handle the case when block_size is zero
    ...

Conclusion

The division by zero vulnerability in the SpaceToDepth TFLite operator of TensorFlow can be exploited by an attacker to cause a crash or potentially execute arbitrary code. Users are advised to update their TensorFlow installations to the latest patched version or upgrade to tensorflow-cpu package version 2.4.3 or later. For further assistance or support in vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for tensorflow-cpu →

Share this vulnerability

FAQ

TensorFlow is an open source platform for machine learning that provides a comprehensive set of tools, libraries, and resources for building and deploying machine learning models.

The SpaceToDepth TFLite operator is a component of TensorFlow that allows for rearranging data in a tensor. It is commonly used in various machine learning applications.

The vulnerability occurs in the Prepare step of the SpaceToDepth TFLite operator, where it fails to check for a zero value before performing division. This allows an attacker to trigger a division by zero error by providing a crafted model with a zero block_size parameter.

The impact of this vulnerability depends on the context in which TensorFlow is used. In some scenarios, it may allow an attacker to cause a denial of service (DoS) by crashing the application or potentially execute arbitrary code.

To fix this vulnerability, users should update their TensorFlow installations to the latest patched version. For users of the tensorflow-cpu package on PyPI, upgrading to version 2.4.3 or later will resolve the vulnerability.

Related vulnerabilities

Recent vulnerabilities recorded for tensorflow-cpu.

How To Fix

Latest published version: 2.21.0 as of 22 Oct 2026

pip install --upgrade "tensorflow-cpu==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.2.0rc0 2.2.0rc0
    pip install --upgrade "tensorflow-cpu==2.2.0rc0"
  • >= 2.2.0, < 2.3.0rc0 2.3.0rc0
    pip install --upgrade "tensorflow-cpu==2.3.0rc0"
  • >= 2.3.0, < 2.3.4 2.3.4
    pip install --upgrade "tensorflow-cpu==2.3.4"
  • >= 2.4.0, < 2.4.3 2.4.3
    pip install --upgrade "tensorflow-cpu==2.4.3"

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