167 Commits

Author SHA1 Message Date
guoling acadaa53a1 Fix IV reuse in encrypted single-key updates
Append encrypted updates so existing compaction handles IV rotation and sync, avoiding a synchronous flush on every update.

Add regression tests. Profiled on iPhone.
2026-10-14 16:34:30 +08:00
guoling 0aa6e2deb4 Fix removeStorage lock ordering
Close the cached instance before acquiring the deletion flock, matching the instance-mutex-before-file-lock order used by writers. Retain the independent CRC descriptor and cross-process exclusion during deletion.

Document instance lifetime requirements and add deterministic regression coverage for writer ordering, cached and uncached removal, and cross-process exclusion. The test passes under ASan and UBSan and detects the original lock inversion.
2026-10-14 15:56:26 +08:00
guoling a72006d149 Optimize borrowed value storage and reject self-import 2026-10-08 16:17:57 +08:00
Qutrek e3a2a9e610 Copy borrowed values when importing into an encrypted store
importFrom() passes the destination no-copy views of the source's values
(KeyValueHolderCrypt::toMMBuffer() / KeyValueHolder::toMMBuffer()). An
encrypted destination keeps a value that is not stored as an offset with
KeyValueHolderCrypt(MMBuffer &&), which adopted the buffer's pointer without
checking that the buffer owns it, and freed it later on remove, overwrite or
clearAll(): a free of memory inside the source's map node or mmap, or a
double free of the source's heap buffer.

Copy a no-copy buffer instead of adopting it. Add a unit test importing plain
and encrypted stores into AES-128 and AES-256 destinations.
2026-10-02 06:09:16 +03:00
guoling 7b3024a659 Fix importFrom lock-order deadlock #1688 2026-09-14 16:10:01 +08:00
guoling 0d85678165 Load expiration state before encoding the first value write
A first set after reopening can encode without the expiration suffix and still report success, leaving an unreadable value. Move the existing write locks and load check ahead of expiry-dependent encoding in each setter path, without adding lock acquisitions or scalar buffers. Route encoded vectors through the existing expiration helper so public templates do not need lock internals.

Keep a minimal set-succeeds/read-fails regression separate from the setter-overload coverage. Both explicitly avoid warming the lazy instance before set.
2026-09-07 16:27:58 +08:00
guoling 023914a0c4 Honor expiration when reading and enumerating read-only stores
Read the expiration flag before the read-only metadata return. Filter expired entries in memory for count/allKeys instead of using fullWriteback, which refuses read-only stores. Test each API as the first operation on a fresh instance, for plain and encrypted stores, and verify filtering leaves stored entries intact.
2026-09-07 16:25:11 +08:00
guoling 22b730c4c0 Load expiration state before the first value read
A reopened instance starts with expiration disabled in memory. Load metadata before selecting the raw or expiration-aware read path; otherwise the first getter can return an expired value. Move the existing load check rather than adding another one.
2026-09-07 16:23:59 +08:00
guoling b9341f1249 Finish partial and interrupted Linux sendfile transfers 2026-09-07 16:04:38 +08:00
guoling 93bac98a7c Complete short and interrupted POSIX file copies 2026-09-07 16:04:38 +08:00
guoling 03ad243b8a Count only successful writes during import 2026-09-07 16:04:38 +08:00
guoling 584a461cde Adopt validated fallback lengths during read-only recovery 2026-09-07 16:04:38 +08:00
guoling 6bd8a3e272 Refresh lazy mappings and validate metadata before cached restore 2026-09-07 16:04:38 +08:00
guoling 3edae0c458 Reject unrepresentable keys when removing encryption 2026-09-07 15:39:38 +08:00
guoling cb8f9b3953 Bound aggregate size before expiration migration 2026-09-07 10:24:56 +08:00
guoling 998c51baca Support unsigned protobuf value lengths 2026-09-04 16:56:43 +08:00
guoling 0a0c596084 Handle undersized mapped MMKV files 2026-09-04 16:56:00 +08:00
guoling ed3ef20383 Validate current MMKV size from metadata 2026-09-04 16:56:00 +08:00
guoling 48fa4337c9 Validate expiration migration while packing 2026-09-04 16:55:59 +08:00
guoling eae63c9865 Prevent plain KeyValueHolder size overflow 2026-09-03 17:04:49 +08:00
guoling ebc106eba4 Fix limited moves of small MMBuffer 2026-09-03 17:02:59 +08:00
guoling baf36b8695 Refine v2.4.2 hardening fixes 2026-08-20 21:42:19 +08:00
guoling c79b7a59d5 Harden backup and restore file handling 2026-08-05 13:39:29 +08:00
guoling 7b20c03c34 Harden encrypted write and key handling 2026-08-05 13:39:29 +08:00
guoling fd0b664940 Fix KMP expiration and UTF-8 consistency 2026-08-05 13:39:29 +08:00
guoling 8e9883ef6f Fix one-year expiration constants 2026-08-04 21:40:24 +08:00
guoling c21236d085 Harden directory walking for long paths 2026-08-04 21:32:25 +08:00
guoling dc9a604498 Harden encrypted MMKV key lifecycle 2026-08-04 21:28:36 +08:00
guoling 4e3535f2c8 Harden MMKV close lifecycle handling #1669 2026-07-29 14:57:14 +08:00
guoling f3b27766a2 fix MMKV instance lifecycle handling #1669 2026-07-28 19:35:21 +08:00
guoling 5892e0ff3b fix expireDuration overflow bug #1665 2026-06-02 19:06:09 +08:00
guoling de70a23783 Fix oversized key corrupting data due to uint16_t overflow in KeyValueHolder
Keys longer than 65531 bytes cause keySize and computedKVSize (both uint16_t)
to wrap around, silently corrupting the internal offset so that subsequent reads
return garbage. Reject keys exceeding the safe threshold (UINT16_MAX - 4) at
all write and parse entry points.
2026-04-08 16:08:59 +08:00
guoling 7224f0aa8f Fix -Wmissing-braces 2026-03-27 16:23:03 +08:00
guoling 58920f50e1 update C++ demo code with MMKVHandler 2026-03-25 12:25:12 +08:00
guoling 050d8c874f add NameSpace to c bridge 2026-03-24 19:44:51 +08:00
guoling 3f2b3999f4 Add universal C interface (cbridge) for MMKV Core
Provide a language-agnostic C99 bridge using standard C types (const char*,
void*, int64_t, etc.) so MMKV Core can be consumed from C-only environments

- Core/cbridge/MMKVBridge.h: pure C header with mmkv_ prefixed API
- Core/cbridge/MMKVBridge.cpp: implementation wrapping MMKV C++ API
- POSIX/demo/demo_c.c: pure C demo exercising all API surface
- CMakeLists.txt updates for core library and demo_c target
2026-03-24 13:28:38 +08:00
guoling 9348a93f26 refactor callback system into unified MMKVHandler across all platforms
Replace 4 separate static function pointers (LogHandler, ErrorHandler,
ContentChangeHandler, ContentLoadedHandler) with a single MMKVHandler
abstract class in Core C++. Update all 6 platform wrappers (iOS, Android,
OHOS, Python, Golang, Flutter) to use adapter classes bridging to the new
unified handler. Add onMMKVContentLoadSuccessfully callback to Android,
OHOS, Flutter, Python and Golang where it was previously missing.
2026-03-18 12:40:05 +08:00
guoling d90f664a2e add DefaultMMKVWithConfig() for golang 2026-03-18 12:39:06 +08:00
guoling e03452f006 add all-in-one config for golang 2026-03-06 16:17:05 +08:00
guoling 1915d892f1 add MMKVConfig 2026-02-05 17:21:53 +08:00
guoling f6bfc28130 add aes256 option on golang with breaking changes on API 2025-12-01 18:13:20 +08:00
guoling 5c2bce40a3 add reKey testcase on POSIX/Win32 2025-12-01 17:05:10 +08:00
guoling 3163817697 fix single key override bug on upgrading from a v1.1.x version #1605 2025-11-24 16:07:16 +08:00
guoling 3867fec5fa test multi-process lazy load bug on file size change 2025-11-24 12:10:51 +08:00
guoling 8b7eb242cb fix readonly crash #1597 2025-10-21 16:45:32 +08:00
guoling 4ad7236e0c dont depend on OS close() to unlock file locks, for Linux/Android flock() is buggy with mmap() 2025-05-07 14:23:41 +08:00
guoling dcfbc83f1c add importFrom() for Python/Golang 2025-04-25 15:23:24 +08:00
guoling 5a5805cdbc add checkExist() for Golang 2025-04-22 20:27:44 +08:00
guoling a7d70e187a NameSpace works on POSIX 2025-01-07 20:32:36 +08:00
tulip 068ca225ef feat: fix the link error on armv8.
fix "unknown reference crc32" link error on armv8.
2025-01-04 11:53:06 +08:00