You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Root Cause Analysis
The crash occurs at metadata.c:244:
assert(((uintptr_t)entry % 8) == 0);
The issue: LMDB does not guarantee 8-byte alignment for stored values. When values are written to LMDB, they're stored contiguously within B-tree pages. While each page is aligned, individual key-value pairs within the page may start at any offset.
Why it affects only certain databases:
- Fresh databases happen to have metadata stored at aligned addresses (by chance)
- Older databases with more data have metadata at various offsets, some of which are not 8-byte aligned
The assertion was added in commit e90d933c ("metadata: add online metadata counts") as a defensive check, but it's incompatible with how LMDB stores data.
Technical Details
1. ndb_get_note_meta() returns a pointer directly into LMDB's memory-mapped file
2. The ndb_note_meta and ndb_note_meta_entry structs are packed (#pragma pack(push, 1))
3. The assertion expects all entry pointers to be 8-byte aligned
4. LMDB doesn't guarantee this alignment
Activity
linear commentedon Dec 30, 2025
NDB-99
alltheseas commentedon Dec 30, 2025
alltheseas commentedon Dec 30, 2025
Summary:
alltheseas commentedon Dec 30, 2025
Root Cause Analysis
The padding strategy doesn't work because LMDB adds per-node overhead:
The MDB_node header size varies:
Even on 64-bit, it's not guaranteed - it depends on LMDB compile options and version.
The Math (64-bit case)
Node header: 8 bytes
Key: 32 bytes
────────────────────
Total: 40 bytes (before value)
40 % 8 = 0 ✓ (happens to align)
The Math (32-bit case)
Node header: 4 bytes
Key: 32 bytes
────────────────────
Total: 36 bytes (before value)
36 % 8 = 4 ✗ (misaligned!)
Why iOS crashes
Even though modern ARM64 handles most misaligned access, crashes can occur from:
Solutions
If alignment must be global, the options are:
The fundamental issue: LMDB cannot guarantee 8-byte value alignment without controlling the node header size, which is internal to LMDB.
Would the dev consider switching META db to MDB_INTEGERKEY like NOTE and PROFILE dbs use?
Sources: