-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Security: Out-of-bounds read in importshp plugin, due to mismatched sizes in DBF file header #1481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
As more than a year has passed since report, I've taken the liberty of requesting a CVE for this vulnerability. Please consider updating the embedded |
CVE-2023-30259 has been assigned to this vulnerability. |
The code quality of the shapelib is not good. Should we remove it from LibreCAD? If it's still relevant, someone should rewrite the lib by safer implementation:
|
I agree, we simply remove the |
CVE-2023-30259 appears to have assigned for this issue |
If anybody is missing the |
Is GDAL ( |
Summary
An out-of-bounds read on a heap buffer in the
importshp
plugin may allow an attacker to read unintended data.Cause
A DBF file has the following structure:
Each record contains all fields, in order, and thus each record is of the same size.
The
dbfopen.c
module parses the file and field headers into an internal structure, saving therecord length
aspsDBF->nRecordLength
as well as calculating the byte offset of each field within the record using each field's individualfield length
. These offsets are stored in the arraypsDBF->panFieldOffset[]
.To access file data, the buffer
psDBF->pszCurrentRecord
is allocated on the heap at dbfopen.c:487, and given the sizenRecordLength
which comes straight from the input file.When a record is accessed, at dbfopen.c:1000, the offset from the data buffer is based on the
field length
(as precomputed intopsDBF->panFieldOffset[]
) and the length of the transfer is directly taken from thefield length
.There is no sanity check on the
nRecordLength
, which means it can be significantly smaller than the actual size of a record (the sum of all field lengths). As a result, an input file with a smallnRecordLength
causes a small heap buffer to be allocated, while a set of largefield length
can make thestrncpy()
copy more data than intended, reading outside the bounds of the heap buffer.Steps to reproduce
dbfopen.c:1000
Megatext
fields in each dropdownWhen the breakpoint triggers, observe the parameters to
strncpy
and verify that the size parameter exceeds the allocated size (nRecordLength
) of the source buffer, and/or that the offset frompabyRec
leads to the source starting outside the buffer.The attached proof of concept has been modified to trigger the bug, but does not always lead to a crash. The actual record size is quite large, consisting of several 255 byte data fields, but the header sets
nRecordLength = 48
Impact
Possible leak of protected data. An out-of-bounds read can be used to bypass automatic security features such as stack canaries and pointer encryption.
Proposed mitigation
Update the bundled
shapelib
with an up-to-date version from OSGeo/shapelib, which includes a sanity check for the record length in the DBF header.Vulnerable version
The text was updated successfully, but these errors were encountered: