551 Commits

Author SHA1 Message Date
guoling 522cf55fa1 Prepare for v2.4.3 hotfix 2026-10-15 19:40:49 +08:00
guoling 2d654ef733 Fix expired-key enumeration 2026-10-15 10:42:33 +08:00
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 32056220d4 Skip unused key wipe for decryptor clones 2026-09-07 10:24:56 +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 bba2dabd03 Reject oversized encrypted keys before decryption 2026-09-07 09:25:29 +08:00
guoling 998c51baca Support unsigned protobuf value lengths 2026-09-04 16:56:43 +08:00
guoling 0f688fd15f Complete interrupted and partial zero-fill writes 2026-09-04 16:56:00 +08:00
guoling 77c3e7d2e0 Require complete whole-file reads 2026-09-04 16:56:00 +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 a444b13449 Reject oversized keys in Apple decoders 2026-09-03 17:03:33 +08:00
guoling c9f527f489 Reset detached MMBuffer without unaligned access 2026-09-03 17:03:18 +08:00
guoling ebc106eba4 Fix limited moves of small MMBuffer 2026-09-03 17:02:59 +08:00
guoling 3938c95707 Use do-while for random IV reads 2026-08-20 22:17:00 +08:00
guoling baf36b8695 Refine v2.4.2 hardening fixes 2026-08-20 21:42:19 +08:00
guoling 6df31b7c0b Prepare for v2.4.2 hotfix 2026-08-20 17:42:52 +08:00
guoling 86d1fe6d02 Fix Windows C bridge compilation #1681 2026-08-18 20:24:46 +08:00
qr243vbi 2b2f9deaf5 Update PBUtility.h 2026-08-09 11:45:07 +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 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 92bd98dca0 Fix secure wipe build failure on iOS #1675
Avoid the optional memset_s and explicit_bzero APIs by using volatile byte stores on non-Windows platforms.
2026-07-31 11:14:46 +08:00
guoling 4287c37f45 prepare for v2.4.1 2026-07-29 20:37:56 +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 e00ecf0408 Harden v2.4.1 KMP release packaging
Fix Android and iOS KMP API parity, empty-byte handling, handler behavior, and runtime version metadata. Harden standalone native interop and Maven Central publication, add smoke tests and publishing documentation, and validate the published package on a physical iPhone.
2026-07-28 16:44:46 +08:00
guoling 520a9a189c Add minimal KMP Android and iOS packaging for v2.4.1 2026-06-26 12:02:55 +08:00
guoling 5892e0ff3b fix expireDuration overflow bug #1665 2026-06-02 19:06:09 +08:00
guoling 68901025b1 add log 2026-06-02 16:58:56 +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