CVE-2021-27923

7.5 HIGH

📋 TL;DR

This vulnerability in Pillow (Python Imaging Library) allows attackers to cause denial of service through memory exhaustion by providing specially crafted ICO image files. The library fails to properly validate reported image sizes within ICO containers, leading to excessive memory allocation attempts. Any application using vulnerable Pillow versions to process ICO files is affected.

💻 Affected Systems

Products:
  • Pillow (Python Imaging Library)
Versions: All versions before 8.1.2
Operating Systems: All operating systems running Python with Pillow
Default Config Vulnerable: ⚠️ Yes
Notes: Only affects ICO image processing functionality. Applications must use Pillow's ICO handling capabilities.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Complete service unavailability due to memory exhaustion, potentially causing system crashes or requiring restarts of affected applications.

🟠

Likely Case

Application crashes or hangs when processing malicious ICO files, leading to temporary service disruption.

🟢

If Mitigated

Minimal impact with proper input validation and memory limits in place, though processing may still fail.

🌐 Internet-Facing: MEDIUM - Applications accepting user-uploaded images are vulnerable, but exploitation requires specific ICO file upload.
🏢 Internal Only: LOW - Requires internal users to process malicious files, which is less likely in controlled environments.

🎯 Exploit Status

Public PoC: ⚠️ Yes
Weaponized: LIKELY
Unauthenticated Exploit: ⚠️ Yes
Complexity: LOW

Creating malicious ICO files is straightforward. Public proof-of-concept exists in security advisories.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: 8.1.2 and later

Vendor Advisory: https://pillow.readthedocs.io/en/stable/releasenotes/8.1.2.html

Restart Required: No

Instructions:

1. Update Pillow using pip: 'pip install --upgrade pillow>=8.1.2' 2. Verify installation with 'pip show pillow' 3. Restart any running Python applications using Pillow.

🔧 Temporary Workarounds

Disable ICO processing

all

Modify application code to reject or skip ICO file processing

# In Python code, add ICO format check before processing
if file_format == 'ICO':
    raise ValueError('ICO processing disabled due to security concerns')

Implement memory limits

linux

Use resource limits or container constraints to prevent memory exhaustion

# For Linux systems with systemd
# Add to service file: MemoryMax=512M
# Or use ulimit: ulimit -v 524288

🧯 If You Can't Patch

  • Implement strict file upload validation to reject ICO files
  • Deploy memory monitoring and alerting for abnormal consumption patterns

🔍 How to Verify

Check if Vulnerable:

Check Pillow version with: python -c "import PIL; print(PIL.__version__)" or pip show pillow

Check Version:

pip show pillow | grep Version

Verify Fix Applied:

Confirm version is 8.1.2 or higher: python -c "import PIL; print('VULNERABLE' if tuple(map(int, PIL.__version__.split('.'))) < (8,1,2) else 'PATCHED')"

📡 Detection & Monitoring

Log Indicators:

  • Memory allocation errors
  • Process crashes when handling image files
  • High memory usage spikes

Network Indicators:

  • Uploads of ICO files to image processing endpoints
  • Unusually large file uploads

SIEM Query:

source="application.logs" AND ("MemoryError" OR "out of memory" OR "ICO")

🔗 References

📤 Share & Export