Skip to content

Fix heap out-of-bounds read in dimensional pcpatch WKB parsing - #388

Open
HarshRajSinghania wants to merge 1 commit into
pgpointcloud:masterfrom
HarshRajSinghania:fix/pcpatch-dimensional-wkb-bounds
Open

HarshRajSinghania wants to merge 1 commit into
pgpointcloud:masterfrom
HarshRajSinghania:fix/pcpatch-dimensional-wkb-bounds

Conversation

@HarshRajSinghania

Copy link
Copy Markdown

Summary

Fixes #387.

The dimensional pcpatch WKB parser trusted attacker-controlled per-dimension size fields and could read beyond the supplied WKB buffer in pc_bytes_deserialize(). The caller also advanced using the claimed size without tracking the remaining input length.

What changed

  • Add an explicit bufsize parameter to pc_bytes_deserialize().
  • Reject dimension records shorter than the 5-byte dimension header.
  • Decode the size as signed int32_t and reject negative values.
  • Reject any dimension whose claimed payload exceeds the remaining WKB buffer before allocation/copy.
  • Pass the remaining WKB length through the dimensional parser and subtract each validated serialized dimension.
  • Propagate pc_bytes_deserialize() failures and clean up partially constructed patches.
  • Reject unexpected trailing bytes after all schema dimensions have been consumed.
  • Add top-level WKB header-length validation before reading PCID/compression fields.
  • Stop pc_patch_from_wkb() from continuing into extent/stat computation when a compression-specific parser returns NULL.

Regression coverage

Added CUnit coverage for:

  • A 13-byte buffer claiming a 65536-byte dimension payload.
  • A truncated 4-byte dimension header.
  • A malformed dimensional patch reaching the public patch WKB dispatcher.

The malformed 65536-byte case is the regression for the demonstrated AddressSanitizer heap-buffer-overflow.

Validation

The branch is one commit ahead of master and the diff is limited to the parser/API changes and regression tests. I did not run the full CUnit/PostgreSQL build through this integration, so CI should be treated as the final build/test validation.

No RCE is claimed; the fix addresses the demonstrated out-of-bounds read and the associated oversized-allocation/DoS condition.

This branch has not been deployed

No deployments
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.

Heap out-of-bounds read in dimensional pcpatch WKB deserialization

1 participant