Crashes in compiler optimized code?

For the last two weeks we have made several releases of our app due to higly increased crash rates of our app. Unfortunattely we can't reproduce the issues and we are struggleing to understand the crash reports.


Our two new crashes started to appear when we migrated from xcode 10.1 to xcode 10.3. We then downgraded to 10.1 and the issue dissapeared. A couple of days later we hade to migrate to xcode 11 to fix some urgent ios 13 issues and the crashes reappeared.


From the looks ot the crashlogs (collected by Fabric/Crashlytics) it has something to do with Dictionary and String subscript getter. As you can see in the crashreports the functions are compiler-generated so the line 0 isn't really helpful. We also made a last effort to disable all compiler optimizations to get a clearer picture of the issue, now Apple claims that the app doesn't even start (but it works for our entire team, our testdevices, relatives with iphones etc.)


The issue seems to be present at all iOS devices at all versions of the OS.


Anything that can point us in the right direction would me much appreciated.


Issue 1, String,

Sure we handle strings here, but we tried all sorts of data here. empty string, long strings, shorts string, matching string and non matching string (regex).

# Crashlytics - plaintext stacktrace downloaded by Erik at Sat, 28 Sep 2019 12:28:28 GMT
# Organization: XYZ AB
# Platform: ios
# Application: XYZ
# Version: 11.19.3 (1499)
# Bundle Identifier: com.XYZ.XYZ
# Issue ID: 960e422607dcb9f570452c13f1db287b
# Session ID: 366cbe7f6c8942b5a39d6e53a5befaa6_DNE_0_v2
# Date: 2019-09-28T12:14:00Z
# OS Version: 12.2.0 (16E227)
# Device: iPhone 7
# RAM Free: 3.9%
# Disk Free: 14.2%


#0. Crashed: com.twitter.crashlytics.ios.exception
0  XYZ                        0x102ee6d78 CLSProcessRecordAllThreads + 4315524472
1  XYZ                        0x102ee7160 CLSProcessRecordAllThreads + 4315525472
2  XYZ                        0x102ed69e8 CLSHandler + 4315458024
3  XYZ                        0x102ee537c __CLSExceptionRecord_block_invoke + 4315517820
4  libdispatch.dylib              0x1a03397d4  + 16 + 16
5  libdispatch.dylib              0x1a02e7c18 _dispatch_lane_barrier_sync_invoke_and_complete + 56
6  XYZ                        0x102ee4de8 CLSExceptionRecord + 4315516392
7  XYZ                        0x102ee4c14 CLSExceptionRecordNSException + 4315515924
8  XYZ                        0x102ee4808 CLSTerminateHandler() + 4315514888
9  libc++abi.dylib                0x19fac8838 std::__terminate(void (*)()) + 16
10 libc++abi.dylib                0x19fac88c4 std::terminate() + 84
11 libobjc.A.dylib                0x19fad3d5c _destroyAltHandlerList + 10
12 libdispatch.dylib              0x1a03397e8 _dispatch_client_callout + 36
13 libdispatch.dylib              0x1a02e7004  + 1068 + 1068
14 CoreFoundation                 0x1a0889ec0  + 12 + 12
15 CoreFoundation                 0x1a0884df8  + 1924 + 1924
16 CoreFoundation                 0x1a0884354 CFRunLoopRunSpecific + 436 + 436
17 GraphicsServices               0x1a2a8479c GSEventRunModal + 104 + 104
18 UIKitCore                      0x1cce3bb68 UIApplicationMain + 212 + 212
19 XYZ                        0x102966e1c main + 31 (main.m:31)
20 libdyld.dylib                  0x1a034a8e0  + 4 + 4


--


Fatal Exception: NSRangeException
0  CoreFoundation                 0x1a08f8518 __exceptionPreprocess
1  libobjc.A.dylib                0x19fad39f8 objc_exception_throw
2  CoreFoundation                 0x1a0802c70 -[NSCache init]
3  Foundation                     0x1a1257174 -[NSPathStore2 characterAtIndex:]
4  libswiftCore.dylib             0x1ce54c1a4 specialized _StringGuts.foreignErrorCorrectedUTF16CodeUnit(at:)
5  libswiftCore.dylib             0x1ce54c248 specialized _StringGuts.foreignScalarAlign(_:)
6  XYZ                        0x10298a42c specialized String.subscript.getter ()
7  XYZ                        0x102aafd08 specialized AppLinkComponents.adIdentifierFromUniversalLinkUrl(_:) ()
8  XYZ                        0x102aaced4 AppLinkComponents.adIdentifierFromUrl(_:) ()
9  XYZ                        0x102aac99c AppLinkComponents.init(URL:) + 106 (AppLinkComponents.swift:106)
10 XYZ                        0x102c1238c specialized static HandoffController.continueUserActivity(_:in:appDelegate:) (AppLinkComponents.swift)
11 XYZ                        0x102aa586c @objc AppDelegate.application(_:continue:restorationHandler:) ()
12 GoogleUtilities                0x103f2af10 (Missing)
13 UIKitCore                      0x1cce37860 -[UIApplication activityContinuationManager:continueUserActivity:]
14 UIKitCore                      0x1cd182e84 -[UIActivityContinuationManager _continueUserActivity:]
15 UIKitCore                      0x1cd183b9c __72-[UIActivityContinuationManager handleActivityContinuation:isSuspended:]_block_invoke_3
16 UIKitCore                      0x1cc8c607c -[_UIApplicationModalProgressController _callAndClearDismissalHandlerWasDismissedByUser:]
17 UIKitCore                      0x1cc8c6454 -[_UIApplicationModalProgressController hideAfterMinimumUptimeWithDismissalHandler:]
18 UIKitCore                      0x1cce37504 -[UIApplication activityContinuationManager:hideProgressUIWithCompletion:]
19 UIKitCore                      0x1cd182e1c -[UIActivityContinuationManager _endCurrentActivityContinuationWithCompletion:]
20 UIKitCore                      0x1cd1838f0 __72-[UIActivityContinuationManager handleActivityContinuation:isSuspended:]_block_invoke_2
21 libdispatch.dylib              0x1a0338a38  + 24
22 libdispatch.dylib              0x1a03397d4  + 16
23 libdispatch.dylib              0x1a02e7004  + 1068
24 CoreFoundation                 0x1a0889ec0  + 12
25 CoreFoundation                 0x1a0884df8  + 1924
26 CoreFoundation                 0x1a0884354 CFRunLoopRunSpecific + 436
27 GraphicsServices               0x1a2a8479c GSEventRunModal + 104
28 UIKitCore                      0x1cce3bb68 UIApplicationMain + 212
29 XYZ                        0x102966e1c main + 31 (main.m:31)
30 libdyld.dylib                  0x1a034a8e0  + 4


#0. Crashed: com.twitter.crashlytics.ios.exception
0  XYZ                        0x102ee6d78 CLSProcessRecordAllThreads + 4315524472
1  XYZ                        0x102ee7160 CLSProcessRecordAllThreads + 4315525472
2  XYZ                        0x102ed69e8 CLSHandler + 4315458024
3  XYZ                        0x102ee537c __CLSExceptionRecord_block_invoke + 4315517820
4  libdispatch.dylib              0x1a03397d4  + 16 + 16
5  libdispatch.dylib              0x1a02e7c18 _dispatch_lane_barrier_sync_invoke_and_complete + 56
6  XYZ                        0x102ee4de8 CLSExceptionRecord + 4315516392
7  XYZ                        0x102ee4c14 CLSExceptionRecordNSException + 4315515924
8  XYZ                        0x102ee4808 CLSTerminateHandler() + 4315514888
9  libc++abi.dylib                0x19fac8838 std::__terminate(void (*)()) + 16
10 libc++abi.dylib                0x19fac88c4 std::terminate() + 84
11 libobjc.A.dylib                0x19fad3d5c _destroyAltHandlerList + 10
12 libdispatch.dylib              0x1a03397e8 _dispatch_client_callout + 36
13 libdispatch.dylib              0x1a02e7004  + 1068 + 1068
14 CoreFoundation                 0x1a0889ec0  + 12 + 12
15 CoreFoundation                 0x1a0884df8  + 1924 + 1924
16 CoreFoundation                 0x1a0884354 CFRunLoopRunSpecific + 436 + 436
17 GraphicsServices               0x1a2a8479c GSEventRunModal + 104 + 104
18 UIKitCore                      0x1cce3bb68 UIApplicationMain + 212 + 212
19 XYZ                        0x102966e1c main + 31 (main.m:31)
20 libdyld.dylib                  0x1a034a8e0  + 4 + 4


#1. io.answers.EventQueue (QOS: BACKGROUND)
0  libsystem_kernel.dylib         0x1a0497a5c lstat + 8
1  Foundation                     0x1a1325e28 _NSFileExistsAtPath + 192
2  Foundation                     0x1a1259a84 -[NSFileManager fileExistsAtPath:] + 120
3  XYZ                        0x102ef3880 -[ANSMetadata computeIsJailbroken] + 4315576448
4  XYZ                        0x102ef35e8 -[ANSMetadata initWithFabric:betaToken:] + 4315575784
5  XYZ                        0x102efcb8c __56-[ANSAnswersController initWithBetaToken:rootDirectory:]_block_invoke + 4315614092
6  Foundation                     0x1a135cf68 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 16
7  Foundation                     0x1a1269420 -[NSBlockOperation main] + 72
8  Foundation                     0x1a1268908 -[__NSOperationInternal _start:] + 740
9  Foundation                     0x1a135ecec __NSOQSchedule_f + 272
10 libdispatch.dylib              0x1a02e77f0 _dispatch_block_async_invoke2 + 104
11 libdispatch.dylib              0x1a03397d4  + 16 + 16
12 libdispatch.dylib              0x1a02de018 _dispatch_continuation_pop$VARIANT$mp + 412
13 libdispatch.dylib              0x1a02dd6dc _dispatch_async_redirect_invoke + 600
14 libdispatch.dylib              0x1a02ea02c _dispatch_root_queue_drain + 372
15 libdispatch.dylib              0x1a02ea8d0 _dispatch_worker_thread2 + 128
16 libsystem_pthread.dylib        0x1a05191b4 _pthread_wqthread + 464
17 libsystem_pthread.dylib        0x1a051bcd4 start_wqthread + 4


#2. com.google.GoogleConfigService.database
0  libsystem_kernel.dylib         0x1a0497408 fsync + 8
1  libsqlite3.dylib               0x1a0d5b5d4 sqlite3_free_table + 67964
2  libsqlite3.dylib               0x1a0d66014 sqlite3_randomness + 2284
3  libsqlite3.dylib               0x1a0d5aee0 sqlite3_free_table + 66184
4  libsqlite3.dylib               0x1a0d4533c sqlite3_value_text + 23708
5  libsqlite3.dylib               0x1a0d11000 sqlite3_finalize + 3636
6  libsqlite3.dylib               0x1a0d3dce8 sqlite3_step + 65920
7  libsqlite3.dylib               0x1a0d2dd24 sqlite3_step + 444
8  XYZ                        0x102fb78c8 -[RCNConfigDBManager insertMainTableWithValues:fromSource:] + 4316379336
9  XYZ                        0x102fb7604 __77-[RCNConfigDBManager insertMainTableWithValues:fromSource:completionHandler:]_block_invoke + 4316378628
10 libdispatch.dylib              0x1a0338a38  + 24 + 24
11 libdispatch.dylib              0x1a03397d4  + 16 + 16
12 libdispatch.dylib              0x1a02e2320 _dispatch_lane_serial_drain$VARIANT$mp + 592
13 libdispatch.dylib              0x1a02e2e3c _dispatch_lane_invoke$VARIANT$mp + 428
14 libdispatch.dylib              0x1a02eb4a8 _dispatch_workloop_worker_thread + 596
15 libsystem_pthread.dylib        0x1a0519114 _pthread_wqthread + 304
16 libsystem_pthread.dylib        0x1a051bcd4 start_wqthread + 4


#3. Thread
0  libsystem_kernel.dylib         0x1a0496b74 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x1a0519138 _pthread_wqthread + 340
2  libsystem_pthread.dylib        0x1a051bcd4 start_wqthread + 4


#4. com.apple.uikit.eventfetch-thread
0  libsystem_kernel.dylib         0x1a048b0f4 mach_msg_trap + 8
1  libsystem_kernel.dylib         0x1a048a5a0 mach_msg + 72
2  CoreFoundation                 0x1a0889cb4 __CFRunLoopServiceMachPort + 236
3  CoreFoundation                 0x1a0884bc4 __CFRunLoopRun + 1360
4  CoreFoundation                 0x1a0884354 CFRunLoopRunSpecific + 436 + 436
5  Foundation                     0x1a1251fcc -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 300
6  Foundation                     0x1a1251e5c -[NSRunLoop(NSRunLoop) runUntilDate:] + 96
7  UIKitCore                      0x1ccf21540 -[UIEventFetcher threadMain] + 136
8  Foundation                     0x1a137e6e4 __NSThread__start__ + 984
9  libsystem_pthread.dylib        0x1a05182c0 _pthread_body + 128
10 libsystem_pthread.dylib        0x1a0518220 _pthread_start + 44
11 libsystem_pthread.dylib        0x1a051bcdc thread_start + 4


#5. com.google.fira.worker
0  libsystem_kernel.dylib         0x1a0497ffc pread + 8
1  libsqlite3.dylib               0x1a0da4134 sqlite3_rekey + 4676
2  libsqlite3.dylib               0x1a0cf4b98 sqlite3_snprintf + 5864
3  libsqlite3.dylib               0x1a0d17440 sqlite3_log + 3348
4  libsqlite3.dylib               0x1a0dad618 sqlite3_rekey + 42792
5  libsqlite3.dylib               0x1a0dbe620 sqlite3_rekey + 112432
6  libsqlite3.dylib               0x1a0d36658 sqlite3_step + 35568
7  libsqlite3.dylib               0x1a0d2dd24 sqlite3_step + 444
8  XYZ                        0x1030151d0 -[APMSqliteStore validateDatabaseWithError:] + 4316762576
9  XYZ                        0x1030150e0 -[APMSqliteStore openAndValidateDatabase:] + 4316762336
10 XYZ                        0x103010640 -[APMSqliteStore initWithDatabasePath:] + 4316743232
11 XYZ                        0x102fe0684 -[APMDatabase initializeDatabaseResourcesWithContext:databasePath:] + 4316546692
12 XYZ                        0x102fd594c -[APMDatabase initWithDatabaseName:persistedConfig:] + 4316502348
13 XYZ                        0x102fe70c0 __47-[APMMeasurement startMeasurementOnWorkerQueue]_block_invoke + 4316573888
14 libdispatch.dylib              0x1a03397d4  + 16 + 16
15 libdispatch.dylib              0x1a02dceb4 _dispatch_once_callout + 28
16 XYZ                        0x102fe6cac -[APMMeasurement startMeasurementOnWorkerQueue] + 4316572844
17 XYZ                        0x102fe680c -[APMMeasurement setEnabledOnWorkerQueue:] + 4316571660
18 XYZ                        0x103000454 __51-[APMScheduler scheduleOnWorkerQueueBlockID:block:]_block_invoke + 4316677204
19 libdispatch.dylib              0x1a0338a38  + 24 + 24
20 libdispatch.dylib              0x1a03397d4  + 16 + 16
21 libdispatch.dylib              0x1a02e2320 _dispatch_lane_serial_drain$VARIANT$mp + 592
22 libdispatch.dylib              0x1a02e2e3c _dispatch_lane_invoke$VARIANT$mp + 428
23 libdispatch.dylib              0x1a02eb4a8 _dispatch_workloop_worker_thread + 596
24 libsystem_pthread.dylib        0x1a0519114 _pthread_wqthread + 304
25 libsystem_pthread.dylib        0x1a051bcd4 start_wqthread + 4


#6. com.apple.root.background-qos
0  libsystem_kernel.dylib         0x1a048b148 semaphore_timedwait_trap + 8
1  libdispatch.dylib              0x1a02db880 _dispatch_sema4_timedwait$VARIANT$mp + 64
2  libdispatch.dylib              0x1a02dc1d8 _dispatch_semaphore_wait_slow + 72
3  XYZ                        0x10300984c -[APMConditionalUserPropertyController conditionalUserPropertiesWithNamePrefix:filterByOrigin:] + 4316715084
4  CoreFoundation                 0x1a08ffba0 __invoking___ + 144
5  CoreFoundation                 0x1a07e1c90 -[NSInvocation invoke] + 292
6  XYZ                        0x102f17acc -[ABTConditionalUserPropertyController experimentsWithOrigin:] + 4315724492
7  XYZ                        0x102f1a384 -[FIRExperimentController updateExperimentsInBackgroundQueueWithServiceOrigin:events:policy:lastStartTime:payloads:] + 4315734916
8  XYZ                        0x102f1a264 __99-[FIRExperimentController updateExperimentsWithServiceOrigin:events:policy:lastStartTime:payloads:]_block_invoke + 4315734628
9  libdispatch.dylib              0x1a0338a38  + 24 + 24
10 libdispatch.dylib              0x1a03397d4  + 16 + 16
11 libdispatch.dylib              0x1a02ea160 _dispatch_root_queue_drain + 680
12 libdispatch.dylib              0x1a02ea8d0 _dispatch_worker_thread2 + 128
13 libsystem_pthread.dylib        0x1a05191b4 _pthread_wqthread + 464
14 libsystem_pthread.dylib        0x1a051bcd4 start_wqthread + 4


#7. Thread
0  libsystem_pthread.dylib        0x1a051bcd0 start_wqthread + 190


#8. com.apple.CFNetwork.Connection
0  libsystem_kernel.dylib         0x1a0495f08 __psynch_mutexdrop + 8
1  libsystem_pthread.dylib        0x1a0511890 _pthread_mutex_firstfit_wake + 28
2  CoreFoundation                 0x1a0885460 CFRunLoopWakeUp + 276
3  CFNetwork                      0x1a10f2d64 MultiplexerSource::_wakeupRunLoop(__CFRunLoop*, __CFString const*, void*) + 56
4  CFNetwork                      0x1a10f2688 MultiplexerSource::signal(CoreSchedulingSet const*, MultiplexerClient*) + 292
5  CFNetwork                      0x1a10f2550 RunLoopMultiplexer::signal(CoreSchedulingSet const*, MultiplexerClient*) + 68
6  CFNetwork                      0x1a10f1714 RunloopBlockContext::addBlockAndSignal(void () block_pointer) + 152
7  CFNetwork                      0x1a10d8e80 HTTPTransaction::RequestBodyStream::cleanup() + 168
8  CFNetwork                      0x1a10d564c HTTPTransaction::_onqueue_closeAndCleanup() + 44
9  CFNetwork                      0x1a0fcd75c HTTPProtocol::destroyReadStream() + 1436
10 CFNetwork                      0x1a0fcb534 HTTPProtocol::cleanupStreams() + 36
11 CFNetwork                      0x1a0fd2bb8 HTTPProtocol::endEncountered() + 352
12 CFNetwork                      0x1a0fd2304 HTTPProtocol::handleStreamEvent(__CFHTTPMessage*, dispatch_data_s*, CFStreamError const*) + 384
13 CFNetwork                      0x1a10d4fa8 HTTPTransaction::_onqueue_invokeHandler() + 344
14 CFNetwork                      0x1a106bc4c HTTPConnection::_onqueue_responseDataArrived(dispatch_data_s*, CFStreamError, bool) + 280
15 CFNetwork                      0x1a10cc084 HTTPEngine::_readBodyFinish(dispatch_data_s*, CFStreamError, bool) + 184
16 CFNetwork                      0x1a10cc840 HTTPEngine::_deliverBodyBytes(dispatch_data_s*, CFStreamError, bool) + 224
17 CFNetwork                      0x1a10cc50c HTTPEngine::_getBodyIntelligently(void (dispatch_data_s*, CFStreamError, bool) block_pointer) + 860
18 CFNetwork                      0x1a10ca180 HTTPEngine::_readBodyStartNextRead() + 80
19 CFNetwork                      0x1a10cc8d0 HTTPEngine::_deliverBodyBytes(dispatch_data_s*, CFStreamError, bool) + 368
20 CFNetwork                      0x1a10cd1a8 invocation function for block in HTTPEngine::_getBodyIntelligently(void (dispatch_data_s*, CFStreamError, bool) block_pointer) + 144
21 libdispatch.dylib              0x1a0338a38  + 24 + 24
22 libdispatch.dylib              0x1a03397d4  + 16 + 16
23 libdispatch.dylib              0x1a02e2320 _dispatch_lane_serial_drain$VARIANT$mp + 592
24 libdispatch.dylib              0x1a02e2e70 _dispatch_lane_invoke$VARIANT$mp + 480
25 libdispatch.dylib              0x1a02e4108 _dispatch_workloop_invoke$VARIANT$mp + 1960
26 libdispatch.dylib              0x1a02eb4a8 _dispatch_workloop_worker_thread + 596
27 libsystem_pthread.dylib        0x1a0519114 _pthread_wqthread + 304
28 libsystem_pthread.dylib        0x1a051bcd4 start_wqthread + 4


#9. com.twitter.crashlytics.ios.MachExceptionServer
0  libsystem_kernel.dylib         0x1a048b0f4 mach_msg_trap + 8
1  libsystem_kernel.dylib         0x1a048a5a0 mach_msg + 72
2  XYZ                        0x102ed19b4 CLSMachExceptionServer + 4315437492
3  libsystem_pthread.dylib        0x1a05182c0 _pthread_body + 128
4  libsystem_pthread.dylib        0x1a0518220 _pthread_start + 44
5  libsystem_pthread.dylib        0x1a051bcdc thread_start + 4


#10. Thread
0  libsystem_kernel.dylib         0x1a0496b74 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x1a0519138 _pthread_wqthread + 340
2  libsystem_pthread.dylib        0x1a051bcd4 start_wqthread + 4


#11. Thread
0  libsystem_kernel.dylib         0x1a0496b74 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x1a0519138 _pthread_wqthread + 340
2  libsystem_pthread.dylib        0x1a051bcd4 start_wqthread + 4


#12. Thread
0  libsystem_pthread.dylib        0x1a051bcd0 start_wqthread + 190


#13. com.apple.NSURLConnectionLoader
0  libsystem_kernel.dylib         0x1a04969d4 __ulock_wait + 8
1  libsystem_platform.dylib       0x1a0507840 _os_nospin_lock_lock_slow + 172
2  CFNetwork                      0x1a10f2a50 MultiplexerSource::perform() + 52
3  CFNetwork                      0x1a10f28d0 MultiplexerSource::_perform(void*) + 60
4  CoreFoundation                 0x1a088a2bc  + 24 + 24
5  CoreFoundation                 0x1a088a23c  + 88 + 88
6  CoreFoundation                 0x1a0889b24 __CFRunLoopDoSources0 + 176
7  CoreFoundation                 0x1a0884a60  + 1004 + 1004
8  CoreFoundation                 0x1a0884354 CFRunLoopRunSpecific + 436 + 436
9  CFNetwork                      0x1a0e9d74c -[__CoreSchedulingSetRunnable runForever] + 216
10 Foundation                     0x1a137e6e4 __NSThread__start__ + 984
11 libsystem_pthread.dylib        0x1a05182c0 _pthread_body + 128
12 libsystem_pthread.dylib        0x1a0518220 _pthread_start + 44
13 libsystem_pthread.dylib        0x1a051bcdc thread_start + 4


#14. JavaScriptCore bmalloc scavenger
0  libsystem_kernel.dylib         0x1a0495ee4 __psynch_cvwait + 8
1  libsystem_pthread.dylib        0x1a0510cf8 _pthread_cond_wait$VARIANT$mp + 636
2  libc++.1.dylib                 0x19fa6d128 std::__1::condition_variable::__do_timed_wait(std::__1::unique_lock<std::__1::mutex>&, std::__1::chrono::time_point<std::__1::chrono::system_clock, std::__1::chrono::duration<long="" long,="" std::__1::ratio<1l,="" 1000000000l=""> > >) + 96
3  JavaScriptCore                 0x1a7a5f75c std::__1::cv_status std::__1::condition_variable::wait_until<std::__1::chrono::steady_clock, std::__1::chrono::duration<long="" long,="" std::__1::ratio<1l,="" 1000000000l=""> > >(std::__1::unique_lock<std::__1::mutex>&, std::__1::chrono::time_point<std::__1::chrono::steady_clock, std::__1::chrono::duration<long="" long,="" std::__1::ratio<1l,="" 1000000000l=""> > > const&) + 124
4  JavaScriptCore                 0x1a7a5f60c std::__1::cv_status std::__1::condition_variable_any::wait_until<std::__1::unique_lock, std::__1::chrono::steady_clock, std::__1::chrono::duration > >(std::__1::unique_lock&, std::__1::chrono::time_point<std::__1::chrono::steady_clock, std::__1::chrono::duration<long="" long,="" std::__1::ratio<1l,="" 1000000000l=""> > > const&) + 116
5  JavaScriptCore                 0x1a7a5e2a4 bmalloc::Scavenger::threadRunLoop() + 296
6  JavaScriptCore                 0x1a7a5d9a4 bmalloc::Scavenger::Scavenger(std::__1::lock_guard&) + 10
7  JavaScriptCore                 0x1a7a5f3e4 std::__1::__thread_specific_ptr<std::__1::__thread_struct>::set_pointer(std::__1::__thread_struct*) + 38
8  libsystem_pthread.dylib        0x1a05182c0 _pthread_body + 128
9  libsystem_pthread.dylib        0x1a0518220 _pthread_start + 44
10 libsystem_pthread.dylib        0x1a051bcdc thread_start + 4


#15. WebThread
0  libsystem_kernel.dylib         0x1a048b0f4 mach_msg_trap + 8
1  libsystem_kernel.dylib         0x1a048a5a0 mach_msg + 72
2  CoreFoundation                 0x1a0889cb4 __CFRunLoopServiceMachPort + 236
3  CoreFoundation                 0x1a0884bc4 __CFRunLoopRun + 1360
4  CoreFoundation                 0x1a0884354 CFRunLoopRunSpecific + 436 + 436
5  WebCore                        0x1a94de480 RunWebThread(void*) + 600
6  libsystem_pthread.dylib        0x1a05182c0 _pthread_body + 128
7  libsystem_pthread.dylib        0x1a0518220 _pthread_start + 44
8  libsystem_pthread.dylib        0x1a051bcdc thread_start + 4


Issue 2, Dictionary, I can't even see that we are using a Dictionary in our function sizedImageUrls (for some reason I can't post the enitre log)

# Crashlytics - plaintext stacktrace downloaded by Erik at Sat, 28 Sep 2019 12:28:30 GMT
# Organization: XYZ AB
# Platform: ios
# Application: XYZ
# Version: 11.19.4 (1509)
# Bundle Identifier: com.XYZ.XYZ
# Issue ID: a0439209b46a197bf51efc1b0774d65e
# Session ID: 327ccd2fc29749e998158f98233676e1_DNE_0_v2
# Date: 2019-09-28T11:35:00Z
# OS Version: 13.1.1 (17A854)
# Device: iPhone 12,3
# RAM Free: 25.9%
# Disk Free: 40.8%


#0. Crashed: com.apple.main-thread
0  XYZ                        0x104c948e8 specialized Dictionary.subscript.getter (<compiler-generated>)
1  XYZ                        0x104c95b40 specialized ImageUrlProvider.sizedImageUrls(baseUrls:size:backend:completion:) (<compiler-generated>)
2  XYZ                        0x104c942c4 ImageUrlProvider.handleLayoutChange(in:) (<compiler-generated>)
3  XYZ                        0x104c94324 @objc ImageUrlProvider.handleLayoutChange(in:) (<compiler-generated>)
4  XYZ                        0x10494548c -[BLCollectionViewCell layoutSubviews] + 86 (BLCollectionViewCell.m:86)
5  UIKitCore                      0x1ba767abc -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2156
6  libobjc.A.dylib                0x1b5f3faf0 -[NSObject performSelector:withObject:] + 68
7  QuartzCore                     0x1bcd060f4 -[CALayer layoutSublayers] + 292
8  QuartzCore                     0x1bcd063fc CA::Layer::layout_if_needed(CA::Transaction*) + 484
9  UIKitCore                      0x1ba75341c -[UIView(Hierarchy) layoutBelowIfNeeded] + 552
10 UIKitCore                      0x1ba759f60 +[UIView(Animation) performWithoutAnimation:] + 104
11 UIKitCore                      0x1b9b56538 -[UICollectionViewAnimation startWithAnimator:] + 168
12 UIKitCore                      0x1b9b2020c __71-[UICollectionView _updateWithItems:tentativelyForReordering:animator:]_block_invoke_2.2004 + 932
13 UIKitCore                      0x1ba75b6fc +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 576
14 UIKitCore                      0x1ba75bcec +[UIView(UIViewAnimationWithBlocks) animateWithDuration:delay:options:animations:completion:] + 112
15 UIKitCore                      0x1b9b1f760 -[UICollectionView _updateWithItems:tentativelyForReordering:animator:] + 5224
16 UIKitCore                      0x1b9b1944c -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:] + 12908
17 UIKitCore                      0x1b9b15694 -[UICollectionView _updateSections:updateAction:] + 412
18 UIKitCore                      0x1b9b15860 -[UICollectionView reloadSections:] + 68
19 XYZ                        0x104922f2c -[BLAdsListViewController adwatchServiceDidUpdateAdwatches:] + 720 (BLAdsListViewController.m:720)
20 XYZ                        0x104ace394 specialized AdwatchServiceBridge.adwatchService(_:didUpdate:) (<compiler-generated>)
21 XYZ                        0x104ac30b0 closure #1 in closure #2 in AdwatchService.downloadAdwatches(closure:) (<compiler-generated>)
22 XYZ                        0x104d44fb8 thunk for @escaping @callee_guaranteed () -> () (<compiler-generated>)
23 libdispatch.dylib              0x1b5ecfbb0 _dispatch_call_block_and_release + 32
24 libdispatch.dylib              0x1b5ed100c _dispatch_client_callout + 20
25 libdispatch.dylib              0x1b5edccd8 _dispatch_main_queue_callback_4CF + 968
26 CoreFoundation                 0x1b61a4e20 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
27 CoreFoundation                 0x1b619fb7c __CFRunLoopRun + 1980
28 CoreFoundation                 0x1b619f098 CFRunLoopRunSpecific + 480
29 GraphicsServices               0x1c0309534 GSEventRunModal + 108
30 UIKitCore                      0x1ba2bf7ac UIApplicationMain + 1940
31 XYZ                        0x1049cfe2c main + 31 (main.m:31)
32 libdyld.dylib                  0x1b601ef30 <redacted> + 4

Replies

I have made release 30.09.2019

And have also the error in compiler generated code


Foundation
-[NSBigMutableString characterAtIndex:]

4

libswiftCore.dylib

specialized _StringGuts.foreignErrorCorrectedUTF16CodeUnit(at:)

5

libswiftCore.dylib

specialized _StringGuts.foreignScalarAlign(_:)



<compiler-generated> - Line 0
specialized String.subscript.getter


In my code I have tried to get index in string of the selection by use selectedRange:



let srange = Range(txtView.selectedRange, in: txtView.text)!

and it crush in

String(txtView.text[txtView.text.startIndex..<srange.lowerBound])


with the error:


Fatal Exception: NSRangeException


*** -[NSBigMutableString characterAtIndex:]: Index 688 out of bounds; string length 688

specialized String.subscript.getter


May be that code is wrong but it worked early (I do not change it)


One thing more, this bug will appears after my xcode updated to 11 version.



In my code I have tried to get index in string of the selection by use

selectedRange
:
let srange = Range(txtView.selectedRange, in: txtView.text)!

and it crush in

String(txtView.text[txtView.text.startIndex..<srange.lowerBound])

Yeah, that’s tricky stuff. Dealing with ranges like this is hard because of the mapping between

NSString
, which always uses UTF-16, and Swift’s
String
, which supports multiple encodings. I can’t see anything obviously wrong with your code, so it’s quite possible you’ve uncovered a bug here.

Can you distill this down into a small test project that also reproduces the problem? If so, I’d appreciate you filing a bug about this, attaching that test project. Please post your bug number here, just for the record.

On the workaround front, try using this:

String(text.prefix(upTo: srange.lowerBound))

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

One thing more, the error happen in project made in xcode 11 (unfortuantly my xcode have auto updated to 11) and only in final signed version of app (testflight or production), so you can not reproduce this bug in the local enviroment. I have downdgrade my xcode to 10.3 again and release app. Also It happen not for all strings, but some stirngs with Emoji will fire this bug.

I encountered the same issue.


Fatal Exception: NSRangeException

*** -[NSPathStore2 characterAtIndex:]: index (42) beyond bounds (42)


0 CoreFoundation 0x1f1d4298c __exceptionPreprocess

1 libobjc.A.dylib 0x1f0f1b9f8 objc_exception_throw

2 CoreFoundation 0x1f1c4cbc0 -[NSCache init]

3 Foundation 0x1f26a2054 -[NSPathStore2 characterAtIndex:]

4 libswiftCore.dylib 0x22016b1a4 specialized _StringGuts.foreignErrorCorrectedUTF16CodeUnit(at:)

5 libswiftCore.dylib 0x22016b248 specialized _StringGuts.foreignScalarAlign(_:)

6 AsiaPlayKit 0x1045eef20 specialized URLParser.parseVideoId(from:) (<compiler-generated>)

...


Tried .prefix(upTo: ), and the issue remain the same.


As workaround, I switch the whole project from Optimization for Speed to for Size.

I'm seeing the same issue. Switching to Optimize for Size works for me as a workaround.


It's very easy to reproduce the issue with an NSTextView. I've created a sample app that demonstrates the issue, and submitted a bug report to Apple (FB7347863).

Could you please add steps on how you reproduced this in NSTextView? I am trying to reproduce this issue in our app and so far I haven't been able to, even though we are getting this crash in prod (I have tried the build setting and everything.

Here's the demonstration project:

https://cl.ly/e31057ba3031/Swift%252520Compiler%252520Issue.zip

I can reproduce the issue in the following development environment:

macOS 10.15

Xcode 11.1

iOS 12.4 simulator (no problem for the latest simulator)

Compile with Optimize for Speed


Code to reproduce the issue:

let u = URL(fileURLWithPath: "/1234")

let s = u.lastPathComponent // No problem if hard-code "1234".

print(String(s.utf16[s.utf16.index(s.utf16.startIndex, offsetBy: 0) ..< s.utf16.index(s.utf16.startIndex, offsetBy: 4)])!) // OK

print(s[s.index(s.startIndex, offsetBy: 0) ..< s.index(s.startIndex, offsetBy: 4)]) // Error on iOS 12.4 simulator, when compiled with Optimize for Speed.

print(s[Range(NSMakeRange(0, 4), in: s)!]) // Error on iOS 12.4 simulator, when compiled with Optimize for Speed.


Submitted a bug report to Apple (FB7386690).

Someone pinged me about this so I took a look at the status of ystsoi’s bug. As part of that I discovered the Swift PR for the fix, and I thought I’d post a reference here so that folks can follow along.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi Eskimo. I have two questions:

1. Where can I see the bug FB7386690 to look of its status

2. Does this Swift PR means that the bug now has been resolved and the patch has been applied to swift library and we will not have exceptions in our code now?

The bug still exists after upgraded to Xcode 11.2.


The bug report should be private. There is no reply to the report, and it is still open.

The bug still exists after upgraded to Xcode 11.2.

Right. From the Swift PR we can see that a fix has been identified, it’s now a question as to when that fix will make it into a public Xcode. Unfortunately it missed the 11.2 bus.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
string.makeContiguousUTF8()


is another possible workaround, instead of disabling compiler optimizations.

Thank you a lot, this helped me solve a mysterious crash with certain file names only happening with the app store version of my app only on iOS 12!


Btw, I use Xcode 11.3.1 and the issue still seems to be present.