CVE-2021-29536: TensorFlow Heap Buffer Overflow in QuantizedReshape
Summary
CVE-2021-29536: TensorFlow is an end-to-end open source platform for machine learning. Affects tensorflow across 5 version ranges.
>= 2.2.0, < 2.3.0rc0
< 2.2.0rc0
>= 2.3.0, < 2.3.4
>= 2.4.0, < 2.4.3
< a324ac84e573fba362a5e53d4e74d5de6729933e
Fixed in 4 releases; the minimum fixed version depends on the release line you run. How to fix ↓
Also tracked for
- tensorflow · Bitnami
- tensorflow-cpu · PyPI
- tensorflow-gpu · PyPI
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.
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.
No signup required · Results in about 60 seconds
Background
TensorFlow is an end-to-end open source platform for machine learning. It provides a comprehensive ecosystem of tools, libraries, and resources for developing and deploying machine learning models. TensorFlow is widely used in various domains, including research, industry, and academia. It offers support for both CPU and GPU computations, making it suitable for a wide range of hardware configurations. However, a vulnerability has been discovered in TensorFlow that can lead to a heap buffer overflow in the QuantizedReshape function.
Vulnerability Detail
The vulnerability arises from the assumption made in the implementation of QuantizedReshape that the two threshold arguments passed to the function are always valid scalars. The implementation tries to access the numeric value directly, but if either of these tensors is empty, the .flat<T>() operation results in an empty buffer. Accessing the element at position 0 of this empty buffer causes a heap buffer overflow. An attacker can exploit this vulnerability by passing in invalid thresholds for quantization. The impact of this vulnerability can range from crashing the application to potential remote code execution.
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.2.0rc02.2.0rc0pip install --upgrade "tensorflow==2.2.0rc0" -
>= 2.2.0, < 2.3.0rc02.3.0rc0pip install --upgrade "tensorflow==2.3.0rc0" -
>= 2.3.0, < 2.3.42.3.4pip install --upgrade "tensorflow==2.3.4" -
>= 2.4.0, < 2.4.32.4.3pip install --upgrade "tensorflow==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
There is no specific workaround provided for this vulnerability. However, users can mitigate the risk by validating the thresholds before passing them to the QuantizedReshape function. This can be done by checking the dimensions and values of the tensors to ensure they meet the expected criteria.
Conclusion
The vulnerability in TensorFlow's QuantizedReshape function can lead to a heap buffer overflow when invalid thresholds are passed for quantization. This can result in application crashes or potential remote code execution. It is crucial to upgrade to the fixed versions of TensorFlow or apply the provided patches to mitigate the vulnerability. Regularly monitoring for vulnerabilities in open source packages, such as using Vulert (https://vulert.com), can help ensure the security of your software.
See every vulnerability recorded for tensorflow →
FAQ
TensorFlow is an open source platform for machine learning that provides a comprehensive set of tools and resources for developing and deploying machine learning models.
QuantizedReshape is a function in TensorFlow that performs a reshape operation on quantized tensors. It is commonly used in machine learning models for various tasks.
An attacker can exploit this vulnerability by passing in invalid thresholds for quantization when calling the QuantizedReshape function. This can lead to a heap buffer overflow and potentially allow the attacker to execute arbitrary code or crash the application.
The vulnerability affects TensorFlow versions 2.1.4 and later, including versions 2.2.x, 2.3.x, and 2.4.x. The fix has been included in TensorFlow 2.5.0 and backported to versions 2.4.2, 2.3.3, 2.2.3, and 2.1.4.
To protect your application, it is recommended to upgrade to TensorFlow 2.5.0 or the respective fixed versions (2.4.2, 2.3.3, 2.2.3, or 2.1.4). Additionally, ensure that only valid thresholds are passed to the QuantizedReshape function by validating the dimensions and values of the tensors.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.