30 Commits

Author SHA1 Message Date
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 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 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 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 a7d70e187a NameSpace works on POSIX 2025-01-07 20:32:36 +08:00
guoling ca602a7342 fix POSIX compile error 2020-11-13 21:50:57 +08:00
guoling acdeb9a11c fix POSIX compile error 2020-10-16 21:40:43 +08:00
guoling 0a580aa15e add unit test for Python 2020-09-01 12:16:55 +08:00
guoling db64061642 fix gcc 4.8.5 compile error 2020-04-13 17:02:29 +08:00
guoling e12f0b599d add unit test for POSIX platform 2020-03-23 20:01:33 +08:00