1830 Commits

Author SHA1 Message Date
guoling a2f98d4aea Document OHOS build and harness workflows 2026-10-16 20:01:55 +08:00
guoling 198186350d Fix KMP IDE imports and sample builds 2026-10-16 19:07:58 +08:00
guoling 9cee61ee48 add harness for ohos ArrayBuffer 2026-10-16 15:43:58 +08:00
guoling b8ec9e75e7 Upgrade Android dependencies and build toolchain
Move dependency versions into a catalog and adopt Gradle 9.8.1, AGP 9.4.1, Kotlin 2.4.21, SDK 37, and NDK 30 with JDK 21 daemon criteria.
2026-10-15 21:22:55 +08:00
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 a6423526a5 Xcode 27 auto change 2026-10-15 10:12:34 +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 29bbb179f9 Fix OpenHarmony ArrayBuffer slice validation
Validate numeric ranges, backing-buffer bounds, and typed-array alignment before forming slices. Preserve zero-copy writes and handle empty buffers safely.

Add portable regression coverage of the production callbacks with N-API and MMKV test doubles; 1,144 checks pass under ASan and UBSan.
2026-10-14 15:56:05 +08:00
guoling a72006d149 Optimize borrowed value storage and reject self-import 2026-10-08 16:17:57 +08:00
Guo Ling c83f35b5f9 Merge pull request #1693 from qutrek/fix/import-into-encrypted
Fix importFrom() into an encrypted instance freeing memory it doesn't own
2026-10-08 16:08:40 +08:00
Guo Ling cb9925b566 Merge pull request #1694 from toyeshhm/fix-doc-typos 2026-10-05 21:54:23 +08:00
toyeshhm 9012a9801a Fix undefined variables in README code samples and doc typos
- flutter/mmkv/README.md, OpenHarmony/MMKV/README.md: the reKey sample
  calls kmmkv.reKey(), but the instance is named mmkv
- OpenHarmony/MMKV/README.md: the TypedArray sample calls
  kv.decodeUint8Array() on an undefined kv; use mmkv
- OpenHarmony/MMKV/README.md: AES-258 -> AES-256
- CONTRIBUTING.md: accecpt -> accept, Additionly -> Additionally
2026-10-04 09:08:46 -05: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
Guo Ling cb06b010fa Merge pull request #1690 from santimattius/feat/kmp-android-context-free-initialize
feat(kmp): capture Context via App Startup for zero-argument initialize() on Android
2026-09-14 14:10:48 +08:00
Santiago Mattiauda f16572b570 feat(kmp): capture Context via App Startup for zero-argument initialize() on Android
Add an AndroidX App Startup Initializer that only captures the application
Context on Android (never triggers native init), plus a new
MMKV.Companion.initialize(logLevel) overload that uses it. This matches the
explicit-but-Context-free initialize() contract every other MMKV platform
(iOS/Windows/POSIX/HarmonyOS) already has. Existing Context-taking overloads
are unchanged.

Closes #1689
2026-09-13 21:57:18 -03:00
Guo Ling 272fb67bb9 Merge pull request #1687 from ngnahtn/fix/android-v7a-detach-npe 2026-09-07 17:59:57 +08:00
ngnahtn 46b71fbe22 fix(android): guard onDetachedFromEngine NPE when libmmkv.so missing for ABI
The published com.tencent:mmkv AAR ships native libs for arm64-v8a and
x86_64 only. On an armeabi-v7a / x86 device onAttachedToEngine() throws
UnsatisfiedLinkError from loadLibrary() before `channel` is assigned. The
engine keeps running, but on activity destroy
FlutterEngineConnectionRegistry.removeAll() calls onDetachedFromEngine()
unconditionally -> channel.setMethodCallHandler(null) -> NullPointerException
-> "Unable to destroy activity" -> fatal crash on every app exit for that
whole ABI class.

- Catch the load failure so `channel` is still registered (MMKV method
  calls then fail gracefully through the existing FFI path).
- Null-guard onDetachedFromEngine().
2026-09-07 16:51:36 +07: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 64ac23ceb4 Preserve Android KMP string interoperability 2026-09-07 10:24:56 +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 79b6c97e78 udpate date of v2.4.2 2026-08-21 11:01:58 +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
Guo Ling b911a9c484 Merge pull request #1682 from naivetoby/fix/flutter-mmkv-spm-linking
fix(flutter): keep MMKV FFI symbols visible with SwiftPM
2026-08-20 17:22:03 +08:00