CVE-2022-23585: TensorFlow Memory Leak in PNG Image Decoding
Summary
CVE-2022-23585: Memory leak in decoding PNG images in Tensorflow. Affects tensorflow across 3 version ranges.
< 2.5.3
>= 2.6.0, < 2.6.3
>= 2.7.0, < 2.7.1
Fixed in 2.5.3, 2.6.3 or 2.7.1, depending on the release line you run. How to fix ↓
Also tracked for
- tensorflow · PyPI
- tensorflow · PyPI
- tensorflow-gpu · PyPI
- tensorflow-cpu · 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 developed by Google. It provides a comprehensive ecosystem of tools, libraries, and resources for building and deploying machine learning models. TensorFlow supports various image formats, including PNG. However, a vulnerability has been identified in TensorFlow's PNG image decoding functionality, which can lead to a memory leak if the image is invalid.
Vulnerability Detail
The vulnerability arises when decoding PNG images in TensorFlow. After calling the png::CommonInitDecode(..., &decode) function, allocated buffers are stored in the decode value. These buffers can only be freed by calling png::CommonFreeDecode(&decode). However, certain error cases in the function implementation invoke the OP_REQUIRES macro, which terminates the function execution without allowing for the memory free to occur. This results in a memory leak. The impact of this vulnerability can lead to increased memory usage and potential resource exhaustion.
How To Fix
Fixed versions by release line
The minimum fixed version depends on the release line you run.
-
< 2.5.32.5.3 -
>= 2.6.0, < 2.6.32.6.3 -
>= 2.7.0, < 2.7.12.7.1
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 workaround, users can implement a manual memory deallocation process by calling png::CommonFreeDecode(&decode) in error handling code paths. This ensures that the allocated buffers are freed even if the function execution is terminated prematurely. Here is an example of how the workaround can be implemented in Python:
import tensorflow as tf
# Decode PNG image
def decode_png(image):
decode = tf.png.decode_png(image)
try:
# Process decoded image
...
except Exception as e:
# Handle error
...
# Free allocated buffers
tf.png.CommonFreeDecode(decode)
raise e
# Usage
image_data = ...
decode_png(image_data)
Conclusion
In conclusion, the identified vulnerability in TensorFlow's PNG image decoding functionality can lead to a memory leak and potential resource exhaustion. It is crucial for users to update their TensorFlow installations to the fixed versions once they are released. Implementing the provided workaround can also help mitigate the risk. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for tensorflow →
FAQ
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 vulnerability can result in a memory leak when decoding PNG images in TensorFlow. This can lead to increased memory usage and potential resource exhaustion.
The vulnerability affects TensorFlow versions 2.5.2, 2.6.0, 2.6.1, 2.6.2, and 2.7.0.
The vulnerability will be fixed in TensorFlow 2.8.0. Users are advised to update their TensorFlow installations to the fixed versions once they are released.
Yes, a workaround is available. Users can manually deallocate the allocated buffers by calling png::CommonFreeDecode(&decode) in error handling code paths.
References
Related vulnerabilities
Recent vulnerabilities recorded for tensorflow.