Skip to content

Fix unaligned 8-byte load in GpMurmurHash64A - #2194

Open
reshke wants to merge 1 commit into
apache:mainfrom
reshke:fix-ubsan-gp-hyperloglog-alignment
Open

reshke wants to merge 1 commit into
apache:mainfrom
reshke:fix-ubsan-gp-hyperloglog-alignment

Conversation

@reshke

@reshke reshke commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

UBSan reported an unaligned uint64_t load in GpMurmurHash64A. Read each word with memcpy so input need not have uint64_t alignment, while preserving the little-endian hash computation.

Sanitizer report (UBSan, instrumented build, ANALYZE on a table with short text values):
  gp_hyperloglog.c:897:11: runtime error: load of misaligned address
  0x529000093515 for type 'uint64_t', which requires 8 byte alignment
  #0 GpMurmurHash64A gp_hyperloglog.c:897
  #1 gp_hll_add_element gp_hyperloglog.c:471
  #2 gp_hyperloglog_add_item gp_hyperloglog.c:788
  #3 compute_scalar_stats commands/analyze.c:3968
  #4 do_analyze_rel commands/analyze.c:971
  #5 analyze_rel_internal commands/analyze.c:429

Triggered by ordinary ndistinct estimation during ANALYZE: short varlena values hashed via VARDATA_ANY have a payload offset that is not a multiple of 8. Benign on x86_64, but undefined behavior on strictly aligned targets.

Fixes #ISSUE_Number

What does this PR do?

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change (fix or feature with breaking changes)
  • Documentation update

Breaking Changes

Test Plan

  • Unit tests added/updated
  • Integration tests added/updated
  • Passed make installcheck
  • Passed make -C src/test installcheck-cbdb-parallel

Impact

Performance:

User-facing changes:

Dependencies:

Checklist

Additional Context

CI Skip Instructions


UBSan reported an unaligned uint64_t load in GpMurmurHash64A.
Read each word with memcpy so input need not have uint64_t alignment,
while preserving the little-endian hash computation.

Sanitizer report (UBSan, instrumented build, ANALYZE on a table with
short text values):
  gp_hyperloglog.c:897:11: runtime error: load of misaligned address
  0x529000093515 for type 'uint64_t', which requires 8 byte alignment
  #0 GpMurmurHash64A gp_hyperloglog.c:897
  #1 gp_hll_add_element gp_hyperloglog.c:471
  #2 gp_hyperloglog_add_item gp_hyperloglog.c:788
  #3 compute_scalar_stats commands/analyze.c:3968
  #4 do_analyze_rel commands/analyze.c:971
  #5 analyze_rel_internal commands/analyze.c:429
Triggered by ordinary ndistinct estimation during ANALYZE: short varlena
values hashed via VARDATA_ANY have a payload offset that is not a
multiple of 8. Benign on x86_64, but undefined behavior on strictly
aligned targets.

@leborchuk leborchuk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

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.

2 participants