CVE-2021-39522
📋 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
- LibreDWG
📦 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.
🎯 Exploit Status
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
allTemporarily disable automatic processing of DWG files in applications using LibreDWG.
# Application-specific configuration required
Sandbox file processing
linuxRun 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