Read the MMKV items-size varint instead of assuming a fixed header - #1303
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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