You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The issue arises from the failure to open the file corresponding to the MMKV instance, resulting in a memory mapping address of 0. When the trim function is invoked, there's no validation check for the pointer's validity. It directly copies the actualSize to the pointer location, leading to a null pointer exception. The call chain is as follows: trim() -> clearAll() -> writeActualSize() -> oldStyleWriteActualSize() -> memcpy.
Why did the file fail to open? The error message from the File::open() function is: 2 (No such file or directory). I've conducted the following analysis:
Checking earlier logs, other MMKV files in the same directory can be opened normally, even the meta file corresponding to the problematic MMKV file can be opened. So, it's definitely not because the rootDir doesn't exist or is invalid.
Could it be that the file couldn't be opened due to a lock by another process? I checked the logs of other processes at the same time, and there were no MMKV operation logs, so this is definitely not the reason.
I also found that the same file read exception occurs after multiple launches by the same user.
I even checked whether the filename is valid. It only contains uppercase and lowercase letters, underscores, and numbers, so there's no issue there.
In conclusion, it should be due to an abnormality in the mobile file system.
The language of MMKV
Java
The version of MMKV
v1.2.12
The platform of MMKV
Android
The installation of MMKV
Maven
What's the issue?
A SIGSEGV (SEGV_MAPERR) null pointer exception occurs when the trim() method is called.
CRASHSTACK
MMKV log
Root Cause Analysis
The issue arises from the failure to open the file corresponding to the MMKV instance, resulting in a memory mapping address of 0. When the trim function is invoked, there's no validation check for the pointer's validity. It directly copies the actualSize to the pointer location, leading to a null pointer exception. The call chain is as follows: trim() -> clearAll() -> writeActualSize() -> oldStyleWriteActualSize() -> memcpy.
Why did the file fail to open? The error message from the File::open() function is: 2 (No such file or directory). I've conducted the following analysis:
Checking earlier logs, other MMKV files in the same directory can be opened normally, even the meta file corresponding to the problematic MMKV file can be opened. So, it's definitely not because the rootDir doesn't exist or is invalid.
Could it be that the file couldn't be opened due to a lock by another process? I checked the logs of other processes at the same time, and there were no MMKV operation logs, so this is definitely not the reason.
I also found that the same file read exception occurs after multiple launches by the same user.
I even checked whether the filename is valid. It only contains uppercase and lowercase letters, underscores, and numbers, so there's no issue there.
In conclusion, it should be due to an abnormality in the mobile file system.
原因分析
问题源于无法打开对应MMKV实例的文件,导致内存映射地址为0。当调用trim函数时,没有对指针的有效性进行检查,直接将actualSize复制到指针位置,从而导致空指针异常。调用链如下:trim() -> clearAll() -> writeActualSize() -> oldStyleWriteActualSize() -> memcpy。
文件为什么会打开失败? File::open()函数的错误信息是:2(没有此文件或目录)。我做了以下分析:
检查稍早时间的日志,相同目录下的其他MMKV文件都可以正常打开,甚至问题MMKV文件对应的meta文件也可以正常打开,所以肯定不会是rootDir不存在或者无效。
会不会是其他进程加锁导致了无法打开呢?我检查了同时期其他进程日志,并没有MMKV的操作日志,因此肯定不会是这个原因。
我还发现同个用户在多次启动后,都会出现同个文件的读取异常。
我甚至还检查了文件名是否有效,它只有大小写字母、下划线和数字,所以是没有问题的。
综上,应该是手机文件系统异常导致的。
The suggestion for modification
The trim method should include a validity check for pointers.
修改建议
trim方法应该加上对指针有效性的判断。
The text was updated successfully, but these errors were encountered: