CVE-2022-23585: Memory Leak in TensorFlow when Decoding PNG Images
Summary
CVE-2022-23585: Tensorflow is an Open Source Machine Learning Framework. Affects tensorflow-cpu across 3 version ranges.
< 2.5.3
>= 2.6.0, < 2.6.3
< ab51e5b813573dc9f51efa335aebcf2994125ee9
Fixed in 2.5.3 or 2.6.3, depending on the release line you run. How to fix ↓
Also tracked for
- tensorflow · PyPI
- tensorflow · Bitnami
- tensorflow · PyPI
- tensorflow-gpu · PyPI
The same CVE-2022-23585 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 widely used for developing and training machine learning models. It provides a comprehensive set of tools and libraries for building and deploying machine learning applications. TensorFlow supports various image formats, including PNG, for image processing tasks. However, a vulnerability has been identified in TensorFlow that can lead to a memory leak when decoding PNG images.
Vulnerability Detail
The vulnerability arises during the decoding process of PNG images in TensorFlow. When an invalid image is encountered, TensorFlow can produce a memory leak due to improper handling of allocated buffers. Specifically, after calling the png::CommonInitDecode(..., &decode) function, the decode value contains allocated buffers that can only be freed by calling png::CommonFreeDecode(&decode). However, certain error cases in the function implementation invoke the OP_REQUIRES macro, which abruptly terminates the execution of the function without allowing for the memory free operation. This results in a memory leak. The vulnerability can have significant ramifications, including potential denial-of-service (DoS) attacks and resource exhaustion.
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.5.32.5.3pip install --upgrade "tensorflow-cpu==2.5.3" -
>= 2.6.0, < 2.6.32.6.3pip install --upgrade "tensorflow-cpu==2.6.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 free the allocated buffers by calling png::CommonFreeDecode(&decode) in the error handling code paths. This ensures that the memory is properly released even in cases where the function execution is terminated prematurely. Here is an example of how the workaround can be implemented in Python:
import tensorflow as tf
# Decoding PNG image
image_data = ... # PNG image data
decode = tf.png.decode_png(image_data)
try:
# Perform image processing
...
except Exception as e:
# Handle error and free allocated buffers
tf.png.CommonFreeDecode(decode)
raise e
Conclusion
In conclusion, TensorFlow is susceptible to a memory leak vulnerability when decoding PNG images. This vulnerability can lead to resource exhaustion and potential denial-of-service attacks. The TensorFlow development team has addressed the issue in the upcoming release of TensorFlow 2.8.0 and has backported the fix to earlier versions. Users are strongly advised to upgrade their TensorFlow installations to the latest patched version to mitigate the vulnerability. For further support and assistance with vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for tensorflow-cpu →
FAQ
TensorFlow is an open-source machine learning framework used for developing and training machine learning models. It provides a comprehensive set of tools and libraries for building and deploying machine learning applications.
The vulnerability can result in a memory leak when decoding PNG images in TensorFlow. This can lead to resource exhaustion and potential denial-of-service (DoS) attacks.
The vulnerability affects TensorFlow versions 2.5.3, 2.6.3, and 2.7.1. However, the upcoming release of TensorFlow 2.8.0 will include the fix.
To fix this vulnerability, users should upgrade their TensorFlow installations to the latest patched version, which includes the fix. Specifically, upgrading to TensorFlow 2.8.0 or any of the backported versions (2.7.1, 2.6.3, or 2.5.3) will mitigate the vulnerability.
Yes, a temporary workaround is available. Users can manually free the allocated buffers by calling png::CommonFreeDecode(&decode) in the error handling code paths. However, it is recommended to upgrade to the patched version as soon as possible.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow-cpu.