Skip to content

Read the MMKV items-size varint instead of assuming a fixed header - #1303

Merged
abrignoni merged 2 commits into
mainfrom
fix/mmkv-item-size-varint
Sep 3, 2026
Merged

Read the MMKV items-size varint instead of assuming a fixed header#1303
abrignoni merged 2 commits into
mainfrom
fix/mmkv-item-size-varint

Conversation

@abrignoni

Copy link
Copy Markdown
Owner

The data region of an MMKV store opens with a varint holding the size of the items that follow. The reader assumed it was always four bytes and started the first key at offset 8, so a store whose varint is one to three bytes decoded to zero keys with no error. It now reads the varint and starts after it, ends the region at 4 plus the recorded size, and refuses a store whose .crc meta file records a non-zero AES vector instead of returning garbage keys.

Known-answer tests cover each varint width, the append-mode placeholder, superseded entries, an empty store and an encrypted one.

🤖 Generated with Claude Code

abrignoni and others added 2 commits September 3, 2026 17:57
…ader

The data region of an MMKV store opens with a varint holding the size of
the items that follow. The reader assumed it was always four bytes and
started the first key at offset 8, so a store whose varint is one to
three bytes decoded to zero keys. It now reads the varint and starts
after it, ends the region at 4 plus the recorded size, and refuses a
store whose .crc meta file records a non-zero AES vector instead of
returning garbage keys. Known-answer tests cover each varint width, the
append-mode placeholder, an empty store and an encrypted one.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The committed tests built a fictional file (a CRC at bytes 4 to 8, no
items-size varint) that only passed because the old reader skipped a fixed
eight bytes. They now build a real store, with the items-size varint the
format actually carries, at all four widths it can take. Adds cases for the
append-mode placeholder and for the encrypted-store refusal. The suite fails
against the old reader and passes against the corrected one.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@abrignoni
abrignoni merged commit 65ab811 into main Sep 3, 2026
8 checks passed
@abrignoni
abrignoni deleted the fix/mmkv-item-size-varint branch September 3, 2026 23:02
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.

1 participant