CVE-2016-4009: Integer Overflow in Pillow Allows Heap-based Buffer Overflow

pillow Updated 02 Oct 2025

Summary

13/04/2016
Yes i
Critical
9.8

CVE-2016-4009: Integer overflow in the ImagingResampleHorizontal function in libImaging/Resample.c in Pillow before 3.1.1 allows remote attackers to have unspecified impact via negative values of the new size, which triggers a heap-bas... Affects pillow across 2 version ranges.

< 3.1.1 < 4e0d9b0b9740d258ade40cce248c93777362ac1e

Fixed in 4e0d9b0b9740d258ade40cce248c93777362ac1e. How to fix ↓

Also tracked for

The same CVE-2016-4009 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.

Free scan

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.

Check my app free

No signup required · Results in about 60 seconds

Sponsored Devnack Penetration testing for web, API and mobile Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

Pillow is a popular Python imaging library that provides support for opening, manipulating, and saving many different image file formats. It is widely used in various applications for image processing and manipulation. However, prior to version 3.1.1, Pillow was vulnerable to an integer overflow in the ImagingResampleHorizontal function in the libImaging/Resample.c file. This vulnerability could be exploited by remote attackers through negative values of the new size parameter, leading to a heap-based buffer overflow.

Vulnerability Detail

The integer overflow vulnerability in Pillow arises from a lack of proper input validation in the ImagingResampleHorizontal function. By providing negative values for the new size parameter, an attacker can trigger a heap-based buffer overflow. This can potentially result in arbitrary code execution or denial of service, depending on how the attacker crafts the exploit. The impact of this vulnerability is unspecified, but it poses a significant risk to systems that utilize Pillow for image processing.

How To Fix

Latest published version: 13.0.0 as of 22 Oct 2026

pip install --upgrade "pillow==13.0.0"

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

4e0d9b0b9740d258ade40cce248c93777362ac1e

This is the first release that contains the fix.

pip install --upgrade "pillow==4e0d9b0b9740d258ade40cce248c93777362ac1e"

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

If upgrading to the fixed version is not immediately feasible, a possible workaround is to ensure that only valid and positive values are used for the new size parameter in the ImagingResampleHorizontal function. This can be achieved by implementing input validation checks before calling the function. Below is an example of how this can be done in Python:

# Perform input validation
if new_size <= 0:
    raise ValueError('Invalid new size')

# Call the ImagingResampleHorizontal function with validated input
ImagingResampleHorizontal(image, new_size)

Conclusion

In conclusion, the integer overflow vulnerability in Pillow's ImagingResampleHorizontal function can lead to a heap-based buffer overflow. This can potentially result in arbitrary code execution or denial of service. Users are strongly advised to upgrade to version 3.1.1 or later of Pillow to mitigate the risk. If immediate upgrade is not possible, implementing input validation checks can serve as a temporary workaround. For further support on vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for pillow →

Share this vulnerability

FAQ

The impact of this vulnerability is unspecified, but it can potentially lead to arbitrary code execution or denial of service. It depends on how an attacker exploits the heap-based buffer overflow.

You can use Vulert's playground at Vulert Scanner to check if your application is affected by this vulnerability. Vulert monitors and alerts in real-time for open-source vulnerabilities, using just the Pipfile.lock file.

Yes, the vulnerability was fixed in version 3.1.1 of Pillow. It is recommended to upgrade to this version or later to mitigate the risk.

If upgrading to the fixed version is not immediately feasible, a possible workaround is to implement input validation checks to ensure only valid and positive values are used for the new size parameter in the ImagingResampleHorizontal function. See the 'workaround' section for an example.

You can find more information about this vulnerability in the advisory database maintained by the Python Packaging Authority. The specific advisory for this vulnerability can be accessed at: https://github.com/pypa/advisory-database/blob/main/vulns/pillow/PYSEC-2016-7.yaml

Related vulnerabilities

Recent vulnerabilities recorded for pillow.

How To Fix

Latest published version: 13.0.0 as of 22 Oct 2026

pip install --upgrade "pillow==13.0.0"

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

4e0d9b0b9740d258ade40cce248c93777362ac1e

This is the first release that contains the fix.

pip install --upgrade "pillow==4e0d9b0b9740d258ade40cce248c93777362ac1e"

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback