CVE-2021-29531: Vulnerability in tf.raw_ops.EncodePng in TensorFlow
Summary
CVE-2021-29531: CHECK-fail in tf.raw_ops.EncodePng. 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
- tensorflow · Bitnami
- tensorflow-cpu · PyPI
- tensorflow-gpu · PyPI
The same CVE-2021-29531 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 open-source machine learning framework developed by Google. It provides a comprehensive ecosystem of tools, libraries, and resources for building and deploying machine learning models. The tf.raw_ops.EncodePng function in TensorFlow is responsible for encoding images in PNG format. This vulnerability affects versions 0 to 2.1.4, 2.2.0 to 2.2.3, 2.3.0 to 2.3.3, and 2.4.0 to 2.4.2 of the TensorFlow package.
Vulnerability Detail
The vulnerability, identified as CVE-2021-29531, allows an attacker to trigger a CHECK fail in PNG encoding by providing an empty input tensor as the pixel data. This can be achieved by passing an empty matrix to the tf.raw_ops.EncodePng function. The implementation of the function only checks for the total number of pixels in the image, without validating the content of the tensor. As a result, if the tensor is empty, the associated buffer becomes NULL, triggering a CHECK_NOTNULL assertion in the png::WriteImageToBuffer function. This assertion causes the program to abort, leading to a denial of service (DoS) attack. The vulnerability has a CVSS score of 2.5, indicating a low severity level.
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.42.1.4pip install --upgrade "tensorflow==2.1.4" -
>= 2.2.0, < 2.2.32.2.3pip install --upgrade "tensorflow==2.2.3" -
>= 2.3.0, < 2.3.32.3.3pip install --upgrade "tensorflow==2.3.3" -
>= 2.4.0, < 2.4.22.4.2pip 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 temporary workaround, users can ensure that the input tensor passed to the tf.raw_ops.EncodePng function is not empty. This can be done by checking the dimensions of the tensor and providing valid pixel data. Here is an example in Python:
import tensorflow as tf
image = tf.zeros([1, 1, 3])
image = tf.cast(image, dtype=tf.uint8)
tf.raw_ops.EncodePng(image=image)
In this example, a non-empty tensor with dimensions [1, 1, 3] is created and passed to the EncodePng function.
Conclusion
The vulnerability in tf.raw_ops.EncodePng in TensorFlow allows an attacker to trigger a CHECK fail in PNG encoding, resulting in a denial of service (DoS) attack. It has been assigned CVE-2021-29531 and has a CVSS score of 2.5. Users are advised to update their TensorFlow installations to the patched versions once they become available. In the meantime, a temporary workaround is provided to mitigate the vulnerability. For further support, please contact the TensorFlow team at DevNack.com.
See every vulnerability recorded for tensorflow →
FAQ
The vulnerability allows an attacker to trigger a CHECK fail in PNG encoding, leading to a denial of service (DoS) attack. However, it does not enable remote code execution or unauthorized access to sensitive information.
Versions 0 to 2.1.4, 2.2.0 to 2.2.3, 2.3.0 to 2.3.3, and 2.4.0 to 2.4.2 of the TensorFlow package are affected by this vulnerability.
There is no information available regarding the exploitation of this vulnerability in the wild at the time of this report.
Yes, users can follow the provided workaround to mitigate the vulnerability until they can update their TensorFlow installations to the patched versions.
For further support on vulnerability remediation or any other TensorFlow-related inquiries, you can reach out to the TensorFlow team at info@devnack.com.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.