CVE-2021-40211

7.5 HIGH

📋 TL;DR

This vulnerability in ImageMagick allows attackers to cause a denial of service (DoS) or potentially execute arbitrary code via a division by zero error when processing Enhanced Metafile (EMF) images. It affects systems running vulnerable versions of ImageMagick that process untrusted EMF files. The vulnerability is triggered during EMF file parsing in the ReadEnhMetaFile function.

💻 Affected Systems

Products:
  • ImageMagick
Versions: 7.1.0-4 specifically (though other versions around this may be affected)
Operating Systems: All platforms running ImageMagick
Default Config Vulnerable: ⚠️ Yes
Notes: Any system using ImageMagick to process EMF files is vulnerable. This includes web applications, document processing systems, and image conversion tools.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Remote code execution leading to complete system compromise if the division by zero can be leveraged for memory corruption.

🟠

Likely Case

Denial of service causing ImageMagick to crash when processing malicious EMF files.

🟢

If Mitigated

Limited impact with proper input validation and sandboxing preventing file processing from untrusted sources.

🌐 Internet-Facing: MEDIUM - Web applications processing user-uploaded images via ImageMagick could be vulnerable to DoS attacks.
🏢 Internal Only: LOW - Requires processing of malicious EMF files, which is less common in internal workflows.

🎯 Exploit Status

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

Proof of concept available in GitHub issues. Exploitation requires only a malicious EMF file to be processed by ImageMagick.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: Fixed in ImageMagick 7.1.0-5 and later

Vendor Advisory: https://github.com/ImageMagick/ImageMagick/issues/4097

Restart Required: No

Instructions:

1. Update ImageMagick to version 7.1.0-5 or later. 2. For Linux: Use package manager (apt-get upgrade imagemagick, yum update imagemagick). 3. For Windows: Download updated binaries from ImageMagick website. 4. For source builds: Pull latest code from GitHub repository.

🔧 Temporary Workarounds

Disable EMF coder

all

Remove or disable the EMF file format support in ImageMagick configuration

Edit policy.xml: <policy domain="coder" rights="none" pattern="EMF" />

Input validation

all

Reject EMF files at application level before passing to ImageMagick

🧯 If You Can't Patch

  • Implement strict file type validation to block EMF files from untrusted sources
  • Run ImageMagick in sandboxed/containerized environment with limited privileges

🔍 How to Verify

Check if Vulnerable:

Check ImageMagick version: convert --version | grep Version. If version is 7.1.0-4 or earlier, system is vulnerable.

Check Version:

convert --version | grep Version

Verify Fix Applied:

After update, verify version is 7.1.0-5 or later using convert --version

📡 Detection & Monitoring

Log Indicators:

  • ImageMagick segmentation faults or crashes when processing EMF files
  • Error messages mentioning 'division by zero' or 'ReadEnhMetaFile'

Network Indicators:

  • Unusual uploads of EMF files to web applications

SIEM Query:

process_name="convert" AND (event_type="crash" OR error_message="*division by zero*")

🔗 References

📤 Share & Export