Apple MMKVCore allKeys() truncates keys at embedded NUL bytes

Open Beginner friendly
#1,707 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
86/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp, ios
Domain
database, mobile

Research direction

In Core/MMKV_OSX.cpp lines 477–485, allKeys() builds a string from NSString.UTF8String without a byte count. Read that implementation and check how the Objective-C wrapper enumerates the same key. Preserve the full UTF-8 byte length, then verify that a key containing an embedded NUL is returned intact.

Written by the indexing model from the issue text.

Description

On iOS with MMKVCore 2.4.2, a key containing an embedded NUL can be stored and looked up, but the C++ allKeys() result loses the bytes after the NUL.

In an Objective-C++ iOS app, initialize MMKV with an empty app-local directory and run:

auto* store = mmkv::MMKV::mmkvWithID("nul-key-repro");
const std::string_view key("key\0tail", 8);
const bool saved = store->set(true, key);
const bool found = store->containsKey(key);
const auto keys = store->allKeys();

Both saved and found are true. The returned key is "key", where I expected the original eight bytes. I reproduced the same result when reopening a store written through the Objective-C wrapper, which enumerates the complete key.

In Core/MMKV_OSX.cpp, allKeys() constructs a string from NSString.UTF8String without supplying a byte count. Using the UTF-8 byte length preserves the embedded NUL. Implementation

Dominant language
C++
Stars
18.8k
Forks
2k
Avg merge
1d 7h
Merged PRs (30d)
8

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Tencent/MMKV

All issues in Tencent/MMKV

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.