Skip to content

[Bug]: UBSAN detects misaligned memory access in WalEntry::ReadAdv #3320

@zpf121

Description

@zpf121

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Version or Commit ID

0.7.0

Other environment information

Actual behavior and How to reproduce it

Description:
When building with UndefinedBehaviorSanitizer (UBSAN), infinity fails to start with the following error:

runtime error: member access within misaligned address 0x7a4afc1e50a9
for type 'WalEntryHeader', which requires 8 byte alignment

Root Cause:
In WalEntry::ReadAdv(), the code uses reinterpret_cast to directly access the WAL entry header:

auto *header = reinterpret_cast<WalEntryHeader *>(const_cast<char *>(ptr));

Why it works on x86:
x86 CPUs can handle misaligned memory access (with performance penalty), so the bug doesn't manifest on x86_64. However:

Performance degradation on x86
Potential crashes on ARM
Risk of data corruption

Solution:
Use ReadBuf/ReadBufAdv and WriteBuf functions (which use memcpy) instead of direct struct access. These functions handle unaligned memory safely.

Files affected:
src/storage/wal/wal_entry_impl.cpp

Expected behavior

No response

Additional information

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions