Skip to content

msDBFOpenVirtualFile(): validate field extents against record length - #7571

Open
nvxbug wants to merge 1 commit into
MapServer:mainfrom
nvxbug:dbf-field-extent-bounds
Open

msDBFOpenVirtualFile(): validate field extents against record length#7571
nvxbug wants to merge 1 commit into
MapServer:mainfrom
nvxbug:dbf-field-extent-bounds

Conversation

@nvxbug

@nvxbug nvxbug commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

AddressSanitizer, reading the first attribute of a shapefile whose .dbf header declares a field wider than its records:

==ERROR: AddressSanitizer: heap-buffer-overflow ... READ of size 10
    #1 msDBFReadAttribute mapxbase.c:647
    #2 msDBFReadStringAttribute mapxbase.c:715
0x... is located 0 bytes after 10-byte region
    allocated by msDBFOpenVirtualFile mapxbase.c:178

msDBFOpenVirtualFile() takes nRecordLength from the header (bytes 10-11) to size pszCurrentRecord, but each field's panFieldSize/panFieldOffset come from the field descriptors with no check that they fit inside the record. msDBFReadAttribute() later strncpys panFieldSize bytes from pabyRec + panFieldOffset, so a header whose fields do not fit the record reads past the record buffer on any attribute access (WFS GetFeature, joins, attribute-driven labels).

Reject the file at open time when the last field's offset+size exceeds nRecordLength, the same layout check shapelib applies. Valid .dbf files satisfy offset+size == nRecordLength for the last field, so they are unaffected. The added unit test covers both the rejected and the accepted case.

What are related issues/pull requests?

None.

AI tool usage

Tasklist

  • Make sure code is correctly formatted (cf pre-commit configuration)
  • Add test case(s)
  • Add documentation
  • Review
  • Adjust for comments
  • All CI builds and checks have passed

A .dbf header whose field offsets and sizes exceed the record length made msDBFReadAttribute() strncpy past the record buffer on the first attribute read. Reject such a header at open, as shapelib does.
@nvxbug

nvxbug commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

any update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant