Valet: iOS 15 crash on `specialized static SecItem.copy(matching:)`

Getting intermittent crash reports from devices running on iOS 15. Not sure if this is associated with Security framework or Valet.

Valet version- 4.1.2

I’m using a valet with basic initialisation: let keychain = Valet.valet(with: Identifier.init(nonEmpty: "identifier")!, accessibility: .afterFirstUnlock)

The crash reports highlights line 25 specialized static SecItem.copy<A>(matching:) and Xcode organiser points to a line in code where it’s accessing a string from keychain: keychain.string(forKey: "key")

The stack trace from Crashlytics:

Crashed: com.apple.root.user-initiated-qos
0  libsystem_kernel.dylib         0x79c4 __pthread_kill + 8
1  libsystem_pthread.dylib        0x7434 pthread_kill + 268
2  libsystem_c.dylib              0x1ff64 abort + 164
3  libsystem_malloc.dylib         0x1bac8 _malloc_put + 550
4  libsystem_malloc.dylib         0x1bd64 malloc_zone_error + 104
5  libsystem_malloc.dylib         0x162c8 nanov2_allocate_from_block + 568
6  libsystem_malloc.dylib         0x1536c nanov2_allocate + 128
7  libsystem_malloc.dylib         0x15288 nanov2_malloc + 64
8  libsystem_malloc.dylib         0x5594 _malloc_zone_malloc + 156
9  CoreFoundation                 0xed28 __CFBasicHashRehash + 376
10 CoreFoundation                 0x206e4 __CFBasicHashAddValue + 104
11 CoreFoundation                 0x14200 CFBasicHashAddValue + 2108
12 CoreFoundation                 0x5d340 CFDictionaryAddValue + 348
13 Security                       0x538c der_decode_dictionary + 248
14 Security                       0x13d6c der_decode_plist + 1172
15 Security                       0x115c4 SecXPCDictionaryCopyPList + 120
16 Security                       0x16c8c SecXPCDictionaryCopyPListOptional + 72
17 Security                       0x12aa0 securityd_send_sync_and_do + 136
18 Security                       0xb55e0 cftype_to_bool_cftype_error_request + 160
19 Security                       0x464c __SecItemCopyMatching_block_invoke_2 + 224
20 Security                       0x5030 __SecItemAuthDoQuery_block_invoke + 540
21 Security                       0x3790 SecItemAuthDoQuery + 1292
22 Security                       0x4b98 __SecItemCopyMatching_block_invoke + 144
23 Security                       0xaf58 SecOSStatusWith + 56
24 Security                       0x48b8 SecItemCopyMatching + 400
25 **                             0x1c9c770 specialized static SecItem.copy<A>(matching:) + 4362553200
26 **                             0x1c9eb88 specialized static Keychain.object(forKey:options:) + 4362562440
27 **                             0x1cb0988 Valet.string(forKey:) + 4362635656

PS- lines 25, 26 & 27 shows the app name which I’ve replaced with **.

About this issue

Most upvoted comments

Thank you for digging in, and apologies that I don’t have more actionable thoughts for you in the interim. Please do circle back and let us know what you find.

I’m currently only seeing this on iOS 15.x devices. Not sure if it’s related to Valet either. I’ll do some more debugging to see if I can find out.

image

I went away buy upgrading XCode on my CI. Ot was on 13.0… with 13.2 all looks good.

Thank you!

On Mon, 17 Jan 2022 at 16:11, Dan Federman @.***> wrote:

Thank you for the report! You mention the crash is “similar”, but if it’s not exactly the same as the above can you attach a crash log to this issue? The screenshot is missing a ton of vital information.

Please note that Valet is already thread safe, and copies (and writes) are executed within a locked context: https://github.com/square/Valet/blob/4f7386b9132f6ac78b7f94f6323a8233ea4934f9/Sources/Valet/Internal/SecItem.swift#L40-L42

I haven’t been able to reproduce these crashes locally, nor in the app I ship. That said, the app I ship is not yet using async/await with this code, since Valet has synchronous returns. But as I said above there’s no reason for me to believe that using these new control-flow keywords would be causing a crash here.

Is this crash reproducible for you? Can you create a sample project that reproduces it somewhat reliably? I’d like to investigate, but a lack of reproducible use case is making this difficult.

— Reply to this email directly, view it on GitHub https://github.com/square/Valet/issues/278#issuecomment-1014698795, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAI35UZFLCICIPJG247M72LUWQ5RZANCNFSM5GXCMHSQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>