CVE-2021-39522

8.8 HIGH

📋 TL;DR

CVE-2021-39522 is a heap-based buffer overflow vulnerability in LibreDWG's bit_wcs2len() function. This allows attackers to execute arbitrary code or cause denial of service by processing specially crafted DWG files. Users and applications that process DWG files with affected LibreDWG versions are vulnerable.

💻 Affected Systems

Products:
  • LibreDWG
Versions: All versions through v0.10.1.3751
Operating Systems: All platforms running LibreDWG
Default Config Vulnerable: ⚠️ Yes
Notes: Any application using LibreDWG to parse DWG files is vulnerable. This includes CAD software, file converters, and document management systems.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Remote code execution leading to complete system compromise, data theft, or ransomware deployment.

🟠

Likely Case

Application crash (denial of service) when processing malicious DWG files.

🟢

If Mitigated

Limited impact if file processing occurs in sandboxed environments with proper memory protections.

🌐 Internet-Facing: MEDIUM - Requires file upload/processing capability; not directly network exploitable.
🏢 Internal Only: MEDIUM - Internal users could exploit via malicious files; requires user interaction or automated processing.

🎯 Exploit Status

Public PoC: ⚠️ Yes
Weaponized: LIKELY
Unauthenticated Exploit: ✅ No
Complexity: MEDIUM

Exploitation requires user to open a malicious DWG file or for an application to automatically process such files. Proof-of-concept exists in GitHub issue #255.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: v0.10.1.3752 and later

Vendor Advisory: https://github.com/LibreDWG/libredwg/issues/255

Restart Required: Yes

Instructions:

1. Check current LibreDWG version. 2. Update to v0.10.1.3752 or later via package manager or source compilation. 3. Restart any services using LibreDWG. 4. Recompile any applications linked against LibreDWG.

🔧 Temporary Workarounds

Disable DWG file processing

all

Temporarily disable automatic processing of DWG files in applications using LibreDWG.

# Application-specific configuration required

Sandbox file processing

linux

Run LibreDWG in containerized or sandboxed environments with limited privileges.

docker run --read-only --cap-drop=ALL -v /tmp:/tmp:ro your_app

🧯 If You Can't Patch

  • Implement strict file upload validation and reject suspicious DWG files
  • Deploy application allowlisting to prevent unauthorized code execution

🔍 How to Verify

Check if Vulnerable:

Check if LibreDWG version is ≤0.10.1.3751 using 'dwgread --version' or package manager query.

Check Version:

dwgread --version 2>/dev/null || dpkg -l libredwg 2>/dev/null || rpm -q libredwg 2>/dev/null

Verify Fix Applied:

Confirm version is ≥0.10.1.3752 and test with known malicious DWG files from proof-of-concept.

📡 Detection & Monitoring

Log Indicators:

  • Application crashes with segmentation faults when processing DWG files
  • Unexpected memory access errors in LibreDWG processes

Network Indicators:

  • Unusual outbound connections after DWG file processing
  • File uploads of DWG files to vulnerable endpoints

SIEM Query:

source="application.log" "segmentation fault" AND "dwg" OR source="web.log" file_extension="dwg" AND response_code=500

🔗 References

📤 Share & Export