
Proof-of-concept and analysis for CVE-2026-126497, a heap out-of-bounds write in LibreCAD/libdxfrw R2004 DWG section-page parsing, with ASan reproducer, RCE lab, and patch.
NVD: https://nvd.nist.gov/vuln/detail/CVE-2026-126497
CVE.org: https://www.cve.org/CVERecord?id=CVE-2026-126497
CVSS: 7.8 (High) CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H · 8.5 (High) CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:P/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N
dwgReader18::parseDataPage() in LibreCAD's bundled libdxfrw allocates a
section buffer from the DWG header and then uses a per-page startOffset from
the section map as a raw destination offset:
objData.reset(new duint8[si.pageCount * si.maxSize]);
...
duint8* oData = objData.get() + pi.startOffset;
pi.uSize = si.maxSize;
comp.decompress18(cData.data(), oData, pi.cSize, pi.uSize);
startOffset is never checked against the allocation size, and the
decompressor is told to write maxSize bytes. A crafted AC1018 (DWG R2004)
file can therefore write past the heap buffer. In LibreCAD and Fedora 44
builds startOffset is duint64, so startOffset = 2^64 - delta also writes
before the buffer (backward write).
The base PoC corrupts the glibc top chunk and aborts. In LibreCAD/Fedora
builds the 64-bit startOffset also allows a backward write to a C++ object
placed before the buffer; a controlled lab demonstration against Fedora 44's
dwg2dxf is included.
| Version / build | Result |
|---|---|
| LibreCAD 2.2.0 | Reproduced (bundled libdxfrw) |
| LibreCAD 2.2.1.5 | Reproduced |
| LibreCAD 2.2.1.6 | Reproduced |
codelibs/libdxfrw @ bf80b74 | Reproduced (forward write) |
Fedora 44 libdxfrw-1.1.0-0.11.rc1.fc43 | Reproduced (dwg2dxf + libdxfrw.so.1) |
LibreCAD commit 17ba2b2 and later | Fixed |
LibreCAD/libdxfrw 0c55959 and later master | Fixed |
The official fix is in LibreCAD commit
17ba2b2
(“Bound R2004 DWG page decoding”, PR #3257). No fixed 2.2.x release was
available at publication time.
The section map is parsed by readDwgHeader() / parseSysPage(). Each page
descriptor contains startOffset, read with getRawLong64(). parseDataPage()
does not verify that:
pageCount * maxSize does not overflow the allocation size,startOffset is inside the allocation,startOffset + maxSize is inside the allocation,decompress18()'s output-size guard only bounds writes relative to the
caller-supplied destination and dsize; it cannot know that the destination
itself is outside the real allocation. This is also why the earlier
decompress18() fix for CVE-2021-21898 does not prevent this issue: the
compressed stream is valid.
The PoC changes only the Header section page startOffset, from 0 to
0x1000. The allocation is 0x7400 bytes and the write starts at
objData + 0x1000, so the final 0x1000 bytes land past the allocation.
poc.dwg is a stock AC1018 file with one 8-byte change:
size: 187890
sha256: 70ae31f77d4a657dfa4f489de46048e17b41ef8046f15a48dd6beb2649eb33de
offset: 0x2dc74
change: 00 00 00 00 00 00 00 00
-> 00 10 00 00 00 00 00 00 (startOffset = 0x1000)
Verify the committed artifact, or rebuild it from the original seed:
./generate_poc.py --verify
./generate_poc.py --seed /path/to/example_2004.dwg
Reproduce with ASan:
LIBDXFRW_DIR=/path/to/libdxfrw ./verify.sh
LIBDXFRW_DIR=/path/to/LibreCAD/libraries/libdxfrw ./verify.sh
Expected output:
[PASS] dwgReader18::parseDataPage heap-buffer-overflow reproduced
The full ASan log is written to out/asan.txt:
ERROR: AddressSanitizer: heap-buffer-overflow
WRITE of size 1
dwgCompressor::decompress18
dwgReader18::parseDataPage
dwgReader18::readDwgHeader
dwgR::processDwg
dwgR::read
0 bytes after 29696-byte region
Patched negative control:
LIBDXFRW_DIR=/path/to/patched/libdxfrw EXPECT_SAFE=1 ./verify.sh
On unmodified Fedora 44 dwg2dxf and libdxfrw.so.1, the PoC aborts without
ASan:
exit=134 (SIGABRT)
Fatal glibc error: malloc.c:2371 (sysmalloc): assertion failed ...
Proven:
dwgR::read() path.SIGABRT on real Fedora 44 dwg2dxf and
libdxfrw.so.1, with ASLR enabled and no root.startOffset = 2^64 - delta
targets objData - delta. In Fedora 44 dwg2dxf, dx_iface sits about
0x51e0 bytes before objData and its first qword is a C++ vtable pointer.
run_rce_lab.sh overwrites that pointer with a fake vtable supplied by
LD_PRELOAD; the next virtual call executes a payload.Expected lab output:
[PASS] RCE via backward write: delta=0x51f0 exit=0
uid=1000(dev) ...
RCE_OK
Not proven / limitations:
LD_PRELOAD to map a fake vtable at a fixed
address (a lab condition).dwg2dxf / libdxfrw.so.1.The base PoC is best classified as heap corruption / denial of service. The backward-write experiment proves the primitive can reach a live C++ vtable, but a weaponized preload-free exploit remains future work.
To run the lab, extract Fedora 44 librecad/libdxfrw RPMs into a directory
and point DISTRO_ROOT at it:
DISTRO_ROOT=/path/to/fedora44/root ./run_rce_lab.sh
fix-parseDataPage.patch is a minimal codelibs-compatible patch:
pageCount/maxSize,pageCount * maxSize overflow,startOffset > dataSize || maxSize > dataSize - startOffset.The authoritative LibreCAD fix (17ba2b2) additionally validates the section
size, compression type, page capacity, file bounds, cSize, and uSize, and
uses a capped allocation (0x2f000000).
dxli)