Skip to content

Conversation

@peterstace
Copy link
Owner

Description

Malformed WKB input containing huge element counts (e.g., 0xFFFFFFFF for ring count in a polygon) would cause the parser to attempt allocating gigabytes of memory before discovering there wasn't enough data. This could crash programs processing untrusted WKB input.

The fix validates that sufficient bytes remain BEFORE allocating slices, failing fast with "unexpected EOF" instead of exhausting memory. The existing check in parseLineString was moved before its allocation; the other parsing functions had no such check.

Fixes #678.

Check List

Have you:

  • Added unit tests? Yes.

  • Add cmprefimpl tests? (if appropriate?) N/A

  • Updated release notes? (if appropriate?) Yes.

Related Issue

Malformed WKB input containing huge element counts (e.g., 0xFFFFFFFF for
ring count in a polygon) would cause the parser to attempt allocating
gigabytes of memory before discovering there wasn't enough data. This
could crash programs processing untrusted WKB input.

The fix validates that sufficient bytes remain BEFORE allocating slices,
failing fast with "unexpected EOF" instead of exhausting memory. The
existing check in parseLineString was moved before its allocation; the
other parsing functions had no such check.

Fixes #678.
@peterstace peterstace self-assigned this Jan 16, 2026
@peterstace peterstace requested a review from Copilot January 16, 2026 02:09
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR prevents out-of-memory crashes when parsing malformed WKB input with inflated element counts by validating that sufficient bytes remain before allocating memory.

Changes:

  • Added bounds checking before slice allocation in WKB parsing functions to fail fast with "unexpected EOF" instead of attempting to allocate gigabytes of memory
  • Moved existing check in parseLineString to execute before allocation
  • Added comprehensive test coverage for all geometry types with inflated counts

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
geom/wkb_parser.go Added pre-allocation bounds checks to prevent OOM on malformed input with inflated counts
geom/wkb_test.go Added test cases for all geometry types to verify malformed WKB with inflated counts fails gracefully

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@peterstace peterstace merged commit 29f4248 into master Jan 16, 2026
1 check passed
@peterstace peterstace deleted the fix_wkb_parsing_oom_bug branch January 16, 2026 02:49
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.

WKB Parser Out-of-Memory Bug

2 participants