MMKV icon indicating copy to clipboard operation
MMKV copied to clipboard

std::out_of_range

Open Designerxsh opened this issue 3 years ago • 19 comments

The language of MMKV

Objective-C

The version of MMKV

v1.2.8

The platform of MMKV

iOS

The installation of MMKV

Cocoapods

What's the issue?

#0 Thread

std::out_of_range

(null)

解析原始 0 libc++abi.dylib 0x00000001b4022000 + 77728 2 libc++abi.dylib 0x00000001b4022000 + 89016 3 MyAPP mmkv::CodedInputDataCrypt::readString(mmkv::KeyValueHolderCrypt&) (CodedInputDataCrypt_OSX.cpp:0) 4 MyAPP _ZZN4mmkv11MiniPBCoder12decodeOneMapERNSt3__113unordered_mapIP8NSStringNS_19KeyValueHolderCryptENS_9KeyHasherENS_10KeyEqualerENS1_9allocatorINS1_4pairIKS4_S5_EEEEEEmbENK3$1clESE (MiniPBCoder_OSX.cpp:140) 5 MyAPP mmkv::MiniPBCoder::decodeOneMap(std::__1::unordered_map<NSString*, mmkv::KeyValueHolderCrypt, mmkv::KeyHasher, mmkv::KeyEqualer, std::__1::allocator<std::__1::pair<NSString* const, mmkv::KeyValueHolderCrypt> > >&, unsigned long, bool) (unordered_map:1268) 6 MyAPP mmkv::MiniPBCoder::decodeMap(std::__1::unordered_map<NSString*, mmkv::KeyValueHolderCrypt, mmkv::KeyHasher, mmkv::KeyEqualer, std::__1::allocator<std::__1::pair<NSString* const, mmkv::KeyValueHolderCrypt> > >&, mmkv::MMBuffer const&, mmkv::AESCrypt*, unsigned long) (MiniPBCoder.cpp:53) 7 MyAPP mmkv::MMKV::loadFromFile() (MMKV_IO.cpp:105) 8 MyAPP mmkv::MMKV::checkLoadData() (MMKV_IO.cpp:0) 9 MyAPP mmkv::MMKV::getDataForKey(NSString*) (MMKV_IO.cpp:468) 10 MyAPP mmkv::MMKV::getBool(NSString*, bool) (MMBuffer.h:83)

Designerxsh avatar Aug 25 '21 02:08 Designerxsh

Can you reproduce this crash? Do you have logs of MMKV when this happened?

lingol avatar Aug 25 '21 03:08 lingol

无法复现,也没有MMKV的log。 唯一的信息就是这些堆栈了

Designerxsh avatar Aug 25 '21 07:08 Designerxsh

Then there's nothing we can do about it. Come back when you have more info.

lingol avatar Aug 25 '21 07:08 lingol

你好,我们打开了mmkv的log,收集了 crash 前的信息。

`{ "date": "2021-11-25T14:17:55.055+08:00", "app_id": "com.xxx", "level": "I", "thread": "com.xxx.userdefault.mmkv", "location": "tryResetFileProtection", "message": "protection on [/var/mobile/Containers/Data/Application/72BF2D95-1F82-413F-843C-FDBE64518509/Documents/mmkv/pre.userdefault.store] is NSFileProtectionCompleteUntilFirstUserAuthentication", "uid": "(null)", "os": "iOS 14.4.1", "device_id": "(null)", "device_model": "(null)" } { "date": "2021-11-25T14:17:55.055+08:00", "app_id": "com.xxx", "level": "I", "thread": "com.xxx.userdefault.mmkv", "location": "tryResetFileProtection", "message": "protection on [/var/mobile/Containers/Data/Application/72BF2D95-1F82-413F-843C-FDBE64518509/Documents/mmkv/pre.userdefault.store.crc] is NSFileProtectionCompleteUntilFirstUserAuthentication", "uid": "(null)", "os": "iOS 14.4.1", "device_id": "(null)", "device_model": "(null)", } { "date": "2021-11-25T14:17:55.055+08:00", "app_id": "com.xxx", "level": "I", "thread": "com.xxx.userdefault.mmkv", "location": "loadFromFile", "message": "loading [pre.userdefault.store] with 105950 actual size, file size 262144, InterProcess 0, meta info version:3", "uid": "(null)", "os": "iOS 14.4.1", "device_id": "(null)", "device_model": "(null)", } { "date": "2021-11-25T14:17:55.055+08:00", "app_id": "com.xxx", "level": "I", "thread": "com.xxx.userdefault.mmkv", "location": "loadFromFile", "message": "loading [pre.userdefault.store] with crc 2483258793 sequence 146 version 3", "uid": "(null)", "os": "iOS 14.4.1", "device_id": "(null)", "device_model": "(null)", } { "date": "2021-11-25T14:17:55.055+08:00", "app_id": "com.xxx", "level": "I", "thread": "com.xxx.userdefault.mmkv", "location": "loadFromFile", "message": "loaded [pre.userdefault.store] with 89 key-values", "uid": "(null)", "os": "iOS 14.4.1", "device_id": "(null)", "device_model": "(null)", }

{ "date": "2021-11-25T14:17:55.055+08:00", "app_id": "com.xxx", "level": "I", "thread": "com.apple.main-thread", "location": "tryResetFileProtection", "message": "protection on [/var/mobile/Containers/Data/Application/72BF2D95-1F82-413F-843C-FDBE64518509/Documents/mmkv/com.xxx.dataCache] is NSFileProtectionCompleteUntilFirstUserAuthentication", "uid": "(null)", "os": "iOS 14.4.1", "device_id": "(null)", "device_model": "(null)", } { "date": "2021-11-25T14:17:55.055+08:00", "app_id": "com.xxx", "level": "I", "thread": "com.apple.main-thread", "location": "tryResetFileProtection", "message": "protection on [/var/mobile/Containers/Data/Application/72BF2D95-1F82-413F-843C-FDBE64518509/Documents/mmkv/com.xxx.dataCache.crc] is NSFileProtectionCompleteUntilFirstUserAuthentication", "uid": "(null)", "os": "iOS 14.4.1", "device_id": "(null)", "device_model": "(null)", } { "date": "2021-11-25T14:17:55.055+08:00", "app_id": "com.xxx", "level": "I", "thread": "com.apple.main-thread", "location": "loadFromFile", "message": "loading [com.xxx.dataCache] with 380371 actual size, file size 1048576, InterProcess 0, meta info version:3", "uid": "(null)", "os": "iOS 14.4.1", "device_id": "(null)", "device_model": "(null)", } { "date": "2021-11-25T14:17:55.055+08:00", "app_id": "com.xxx", "level": "I", "thread": "com.apple.main-thread", "location": "loadFromFile", "message": "loading [com.xxx.dataCache] with crc 2337473046 sequence 147 version 3", "uid": "(null)", "os": "iOS 14.4.1", "device_id": "(null)", "device_model": "(null)", } { "date": "2021-11-25T14:17:55.055+08:00", "app_id": "com.xxx", "level": "I", "thread": "com.apple.main-thread", "location": "loadFromFile", "message": "loaded [com.xxx.dataCache] with 141 key-values", "uid": "(null)", "os": "iOS 14.4.1", "device_id": "(null)", "device_model": "(null)", }

{ "date": "2021-11-25T14:17:55.055+08:00", "app_id": "com.xxx", "level": "I", "thread": "com.apple.main-thread", "location": "tryResetFileProtection", "message": "protection on [/var/mobile/Containers/Data/Application/72BF2D95-1F82-413F-843C-FDBE64518509/Documents/mmkv/com.xxx.dataCache.8622977395] is NSFileProtectionCompleteUntilFirstUserAuthentication", "uid": "8622977395", "os": "iOS 14.4.1", "device_model": "iPhone_8_Plus", } { "date": "2021-11-25T14:17:55.055+08:00", "app_id": "com.XXX", "level": "I", "thread": "com.apple.main-thread", "location": "tryResetFileProtection", "message": "protection on [/var/mobile/Containers/Data/Application/72BF2D95-1F82-413F-843C-FDBE64518509/Documents/mmkv/com.xxx.dataCache.8622977395.crc] is NSFileProtectionCompleteUntilFirstUserAuthentication", "uid": "8622977395", "os": "iOS 14.4.1", "device_model": "iPhone_8_Plus", } { "date": "2021-11-25T14:17:55.055+08:00", "app_id": "com.xueXXXqiu", "level": "I", "thread": "com.apple.main-thread", "location": "loadFromFile", "message": "loading [com.XXX.dataCache.8622977395] with 554515 actual size, file size 1048576, InterProcess 0, meta info version:3", "uid": "8622977395", "os": "iOS 14.4.1", "device_model": "iPhone_8_Plus", } { "date": "2021-11-25T14:17:55.055+08:00", "app_id": "com.XXX", "level": "I", "thread": "com.apple.main-thread", "location": "loadFromFile", "message": "loading [com.XXX.dataCache.8622977395] with crc 677708095 sequence 78 version 3", "uid": "8622977395", "os": "iOS 14.4.1", "device_model": "iPhone_8_Plus", } { "date": "2021-11-25T14:17:55.055+08:00", "app_id": "com.XXX", "level": "C", "thread": "com.tencent.bugly.operationQueue (QOS: USER_INTERACTIVE)", "location": "-[PREMediator(PRETrack) attachmentForException:]", "message": "bugly crash:std::out_of_range||(null)||0 libc++abi.dylib 0x00000001bffc4154 0x00000001bffb2000 + 740681 libc++abi.dylib 0x00000001bffc40ec _ZSt9terminatev + 442 libdispatch.dylib 0x00000001ab77b294 0x00000001ab71a000 + 3979723 libdispatch.dylib 0x00000001ab754190 0x00000001ab71a000 + 2379684 FrontBoardServices 0x00000001baeb8e60 0x00000001bae63000 + 3518405 FrontBoardServices 0x00000001baeb8b28 0x00000001bae63000 + 3510166 FrontBoardServices 0x00000001baeb8ffc 0x00000001bae63000 + 3522527 CoreFoundation 0x00000001abac2bf0 0x00000001aba28000 + 6338408 CoreFoundation 0x00000001abac2af0 0x00000001aba28000 + 6335849 CoreFoundation 0x00000001abac1e38 0x00000001aba28000 + 63032810 CoreFoundation 0x00000001ababc3e0 0x00000001aba28000 + 60720011 CoreFoundation 0x00000001ababbba0 CFRunLoopRunSpecific + 57212 GraphicsServices 0x00000001c2824598 GSEventRunModal + 16013 UIKitCore 0x00000001ae3ad2f4 0x00000001ad87f000 + 1172350814 UIKitCore 0x00000001ae3b2874 UIApplicationMain + 16415 Snowball 0x0000000108ecdee0 _ZN5folly6detail15str_to_integralIxEENS_8ExpectedIT_NS_14ConversionCodeEEEPNS_5RangeIPKcEE + 987284016 libdyld.dylib 0x00000001ab79a568 0x00000001ab799000 + 5480", "uid": "8622977395", "os": "iOS 14.4.1", "device_model": "iPhone_8_Plus", }`

Designerxsh avatar Nov 25 '21 07:11 Designerxsh

Can you export the file com.XXX.dataCache.8622977395 and the CRC file com.XXX.dataCache.8622977395.crc on this crash device?

lingol avatar Nov 25 '21 07:11 lingol

用户环境现在拿不到这两个文件。从目前的信息中可以看到问题的产生大大概方向吗? 感谢!

Designerxsh avatar Nov 29 '21 02:11 Designerxsh

If you can't reproduce it & it's not that much report online. You should just ignore it. Without a reproducible case, it's impossible to further investigate.

lingol avatar Nov 29 '21 02:11 lingol

您好,来信已经收到。

devsheng avatar Dec 07 '21 09:12 devsheng

Can you export the file com.XXX.dataCache.8622977395 and the CRC file com.XXX.dataCache.8622977395.crc on this crash device?

你好 ,我们在 crash 设备上收集到出错的文件了,请问如何和你对接帮忙看下问题。

Designerxsh avatar Mar 22 '22 08:03 Designerxsh

Just upload them here as file attechments.

lingol avatar Mar 22 '22 08:03 lingol

Just upload them here as file attechments. 崩溃信息.zip

Designerxsh avatar Mar 22 '22 08:03 Designerxsh

Just upload them here as file attechments. 崩溃信息.zip

Looks like your MMKV is encrypted, did you forget to provide the encryption key inside your zip attachment? I was unable to diagnose the file without the encryption key.

lingol avatar Mar 24 '22 14:03 lingol

By the way, I found that the order of your logs is questionable. For one example,

"2022-03-21T16:44:30.864Z",loadFromFile,"loaded [snb.userdefault.store] with 86 key-values" "2022-03-21T16:44:30.864Z","-[MMKV onMemoryWarning]","cleaning on memory warning snb.userdefault.store"

There's no 'loading xxx' between those two logs. Eighter you have lost it, or the order is not reliable. We recommend using our open-sourced logging tool xlog.

lingol avatar Mar 24 '22 14:03 lingol

And you should provide thread info/thread id for each line of log.

lingol avatar Mar 24 '22 15:03 lingol

Just upload them here as file attechments. 崩溃信息.zip

Looks like your MMKV is encrypted, did you forget to provide the encryption key inside your zip attachment? I was unable to diagnose the file without the encryption key.

秘钥可以通过什么安全的方式发送给你吗?比如邮箱。

Designerxsh avatar Mar 25 '22 07:03 Designerxsh

Sure. [email protected]

lingol avatar Mar 25 '22 07:03 lingol

And you should provide thread info/thread id for each line of log. 崩溃信息_3_25.zip

信息更全,包含 thread 信息

Designerxsh avatar Mar 25 '22 08:03 Designerxsh

That's very vivid logs you provided. However, the order is still questionable. I have filtered out all info relative to the corrupted file:

2022-03-25T02:53:58.537Z,loadFromFile,loading [com.xueqiu.dataCache] with crc 444446063 sequence 916 version 3,com.apple.main-thread

2022-03-25T02:53:58.537Z,loadFromFile,"loading [com.xueqiu.dataCache] with 638676 actual size, file size 1048576, InterProcess 0, meta info version:3",com.apple.main-thread

2022-03-25T02:53:58.537Z,tryResetFileProtection,protection on [/var/mobile/Containers/Data/Application/0BF4F9FF-DCB9-496D-A371-E9BCB8D4811F/Documents/mmkv/com.xueqiu.dataCache] is NSFileProtectionCompleteUntilFirstUserAuthentication,com.apple.main-thread

2022-03-25T02:53:58.537Z,loadFromFile,文件读取失败 com.xueqiu.dataCache,com.apple.main-thread

2022-03-25T02:53:58.536Z,-[MMKV onMemoryWarning],cleaning on memory warning com.xueqiu.dataCache,com.apple.main-thread

2022-03-25T02:53:58.536Z,clearMemoryCache,clearMemoryCache [com.xueqiu.dataCache],com.apple.main-thread

See, the order is wrong. There's no way loadFromFile,文件读取失败 happens before loading [com.xueqiu.dataCache] with 638676 actual size.

You should use a proper logging tools such as our xlog.

And you should upgrade to the latest version of MMKV. v1.2.8 is a bit old.

lingol avatar Mar 25 '22 14:03 lingol

That's very vivid logs you provided. However, the order is still questionable. I have filtered out all info relative to the corrupted file:

2022-03-25T02:53:58.537Z,loadFromFile,loading [com.xueqiu.dataCache] with crc 444446063 sequence 916 version 3,com.apple.main-thread 2022-03-25T02:53:58.537Z,loadFromFile,"loading [com.xueqiu.dataCache] with 638676 actual size, file size 1048576, InterProcess 0, meta info version:3",com.apple.main-thread 2022-03-25T02:53:58.537Z,tryResetFileProtection,protection on [/var/mobile/Containers/Data/Application/0BF4F9FF-DCB9-496D-A371-E9BCB8D4811F/Documents/mmkv/com.xueqiu.dataCache] is NSFileProtectionCompleteUntilFirstUserAuthentication,com.apple.main-thread 2022-03-25T02:53:58.537Z,loadFromFile,文件读取失败 com.xueqiu.dataCache,com.apple.main-thread 2022-03-25T02:53:58.536Z,-[MMKV onMemoryWarning],cleaning on memory warning com.xueqiu.dataCache,com.apple.main-thread 2022-03-25T02:53:58.536Z,clearMemoryCache,clearMemoryCache [com.xueqiu.dataCache],com.apple.main-thread

See, the order is wrong. There's no way loadFromFile,文件读取失败 happens before loading [com.xueqiu.dataCache] with 638676 actual size.

You should use a proper logging tools such as our xlog.

And you should upgrade to the latest version of MMKV. v1.2.8 is a bit old.

截屏2022-03-25 下午11 51 59 我们的项目中catch (std::exception &exception)无法捕获到std::out_of_range异常,但是通过catch(std::out_of_range &exception)可以捕获到,原因不太明确。所以为了避免崩溃,我们在MMKV::loadFromFile()中调用MiniPBCoder::decodeMap()处增加了捕获std::out_of_range代码,"loadFromFile,文件读取失败"日志就来源于此处。

tom555cat avatar Mar 25 '22 15:03 tom555cat

It's fixed in v1.3.2. @tom555cat

lingol avatar Feb 04 '24 09:02 lingol