120 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
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 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 3edae0c458 Reject unrepresentable keys when removing encryption 2026-09-07 15:39:38 +08:00
guoling dd4e36a8f2 Avoid page-size division on 64-bit appends 2026-09-07 10:24:56 +08:00
guoling cb8f9b3953 Bound aggregate size before expiration migration 2026-09-07 10:24:56 +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 439f6537ae Keep MMKV payload growth arithmetic representable 2026-09-04 16:08:23 +08:00
guoling eae63c9865 Prevent plain KeyValueHolder size overflow 2026-09-03 17:04:49 +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 dc9a604498 Harden encrypted MMKV key lifecycle 2026-08-04 21:28:36 +08:00
guoling 4287c37f45 prepare for v2.4.1 2026-07-29 20:37:56 +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 6a55c88536 enhance random iv 2026-03-25 12:46:48 +08:00
guoling f4cb2357bc drop oldstyle actual size downgrade support 2026-03-03 20:10:30 +08:00
guoling fec30f74c7 robust check on encryption mode #1642 2026-02-24 15:21:51 +08:00
guoling 1915d892f1 add MMKVConfig 2026-02-05 17:21:53 +08:00
Guo Ling f6e6fbc5e0 convert log message to utf-8 by (changing src in utf-8) for win32 client 2026-01-30 18:04:08 +08:00
guoling 96390cc85a verify all page in win32 for corrupted file 2026-01-29 15:27:48 +08:00
guoling e439582ab7 protect from m_file not valid for isDiskOfMMAPFileCorrupted() 2025-12-25 12:06:49 +08:00
hossinasaadi 6acdef76d0 fix 2025-12-22 17:56:48 +03:30
hossinasaadi e8dba7762f fix public interface 2025-12-22 15:23:58 +03:30
hossinasaadi df721fa6cd add onMMKVContentLoadSuccessfully to content notify handler 2025-12-21 17:39:57 +03:30
guoling c708914c04 protect from delete file failure on corrupted files 2025-12-18 19:33:30 +08:00
guoling d99404baeb reduce absolutePath() call as much as possible 2025-12-16 18:32:19 +08:00
guoling 8cb70d1123 add aes256 option on mmkv creation 2025-11-27 16:02:49 +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 09c27e6d7b protect from file size change on multi-process load #1599 2025-11-24 11:54:11 +08:00
guoling 8b7eb242cb fix readonly crash #1597 2025-10-21 16:45:32 +08:00
guoling 2ba8ff9bc0 support AES 256 2025-09-24 11:55:35 +08:00
guoling 9ac9c642ac add importFrom() for iOS 2025-04-25 11:48:31 +08:00
guoling 0f745c609d test checkExist() on Win32 2025-04-22 20:53:38 +08:00
guoling 922e08e74a fix crcPath empty bug 2025-04-22 17:04:04 +08:00
guoling 85e64c9422 add checkExist() for Flutter 2025-04-22 16:39:05 +08:00
guoling c2dbd276c2 add checkExist() #1346 2025-04-22 15:15:23 +08:00
guoling c00c3b6006 improve multi-process read robustness by checking actualSize 2025-04-21 14:48:16 +08:00
guoling 8a024dfc3d improve multi-process read efficiency 2025-04-21 14:43:27 +08:00
guoling f23e95c652 support using MMKVCore at Apple platform in pure C++ code 2025-02-14 19:43:48 +08:00