Pillow: TIFF encoder ColorMap plane-size mismatch heap out-of-bounds read
A heap-based out-of-bounds read vulnerability in the Pillow TIFF encoder occurs when saving images with crafted metadata, potentially leading to application crashes.
Triage facts
Revision 1- Applicability
- Pillow (12.3.0)
- Evidence
- Unknown
- Severity
- Medium
- Action
- Elevated
- Sources
- 1 public source
- Freshness
- Revision 1Oct 20, 23:53 UTC
- Detection
- 1 IOC
- Source quality
- A1Likely
Pillow version 12.3.0 is vulnerable to a heap-based out-of-bounds read during the TIFF encoding process. The flaw is triggered when an application opens a TIFF file containing a specific ColorMap (tag 320) and subsequently attempts to save the image while retaining existing metadata. Pillow's TIFF encoder allocates a buffer based on a fixed stride of 256 SHORT values; however, if the image metadata specifies BitsPerSample = 16, the underlying libtiff library expects a significantly larger data volume per plane. This discrepancy causes libtiff to attempt a 131,072-byte read from a 1,536-byte heap-allocated region. While the defect leads to an ASAN-observed out-of-bounds read and process termination, arbitrary memory disclosure or code execution has not been demonstrated.
Attack Chain
- Attacker crafts a malicious TIFF file with
BitsPerSample = 16and a specifically formatted ColorMap containing 768 SHORT entries. - The malicious TIFF file is delivered to a target application that uses the Pillow library to process or convert images.
- The target application invokes
Image.open()to load the malicious file, successfully parsing the TIFF metadata. - The target application performs image processing or transformation operations.
- The target application invokes the
Image.save()function with theformat="TIFF"parameter. - Pillow's
ImagingLibTiffSetFieldfunction allocates a buffer for the ColorMap metadata based on the initial input size. - The libtiff encoder triggers a
memcpyoperation, attempting to copy data based on theBitsPerSamplevalue rather than the allocated buffer size. - The process attempts to read memory outside the allocated heap region, resulting in an out-of-bounds read and immediate process termination.
Impact
Successful exploitation results in the abnormal termination of the host application process, leading to potential denial-of-service for the affected service. The vulnerability requires the application to process and re-save user-supplied image files while retaining metadata.
Recommendation
- Monitor applications using Pillow for unexpected process crashes, specifically those associated with TIFF image processing tasks.
- Implement strict validation of TIFF metadata, specifically
BitsPerSampleandColorMaptags, before invokingImage.save()on untrusted input. - Perform static analysis of source code to identify instances where user-supplied TIFF metadata is blindly passed to the Pillow save path.
- Ensure that the Pillow library is updated to the latest available version if a patch is released to address the buffer allocation logic.
- Audit logging for
AddressSanitizererror reports in test or development environments to proactively identify similar boundary violation defects.
Immediate actions
Check application logs for crashes involving PIL.TiffImagePlugin
Threat Hunt
Identify applications performing TIFF image processing and metadata retention
Data: Application dependency inventory
Mitigations
Upgrade Pillow to the latest available version once a fix is provided
Pillow 12.3.0
Indicators of compromise
1
hash_sha256
| Type | Value |
|---|---|
| hash_sha256 | 5f38e0ead90b97949fb0c98c63f9c68d00ba9181db6631ecb8927376dcc75f4d |