What is causing this crash in NSUserDefaults? - ios

We see a sporadic crash in our user base, during a routine read from NSUserDefaults. The overwhelming majority of users don't experience this problem, and those that do aren't running any particular version of iOS. It seems to have appeared only since we started deploying with Xcode 9.1.
EXC_BAD_ACCESS KERN_PROTECTION_FAILURE 0x000000016efe3fc0
Crashed: com.apple.main-thread
0 libswiftCore.dylib 0x101816d4c #objc _NSContiguousString.length() + 5720
1 CoreFoundation 0x181e2a168 CFStringCompareWithOptionsAndLocale + 96
2 Foundation 0x1828602fc -[NSString isEqualToString:] + 76
3 CoreFoundation 0x181e19558 CFEqual + 596
4 CoreFoundation 0x181e15414 CFBasicHashFindBucket + 344
5 CoreFoundation 0x181e152a0 CFDictionaryGetValue + 224
6 CoreFoundation 0x181ef0c74 -[CFPrefsSearchListSource alreadylocked_copyValueForKey:] + 108
7 CoreFoundation 0x181f8f224 -[CFPrefsSource copyValueForKey:] + 64
8 CoreFoundation 0x181f992c0 __76-[_CFXPreferences copyAppValueForKey:identifier:container:configurationURL:]_block_invoke + 40
9 CoreFoundation 0x181ef44f0 __108-[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:buttConfigurationURL:perform:]_block_invoke + 268
10 CoreFoundation 0x181ef3d0c normalizeQuintuplet + 356
11 CoreFoundation 0x181ef43d8 -[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:buttConfigurationURL:perform:] + 108
12 CoreFoundation 0x181f99258 -[_CFXPreferences copyAppValueForKey:identifier:container:configurationURL:] + 124
13 CoreFoundation 0x181f9bbbc _CFPreferencesGetAppBooleanValueWithContainer + 136
14 Foundation 0x1828517a8 -[NSUserDefaults(NSUserDefaults) boolForKey:] + 112
15 <our code> 0x100d80750 #objc SettingsPersistence.persistedBool.getter (SettingsPersistence.swift:90)
Here's how we retrieve the value (Swift 3, called via Objective C):
fileprivate static let PersistedBoolKey = "persistedBool"
public var persistedBool: Bool {
get {
return UserDefaults.standard.bool(forKey: SettingsPersistence.PersistedBoolKey)
}
set(newPersistedBool) {
UserDefaults.standard.set(newPersistedBool, forKey: SettingsPersistence.PersistedBoolKey)
}
}
I thought it might be a thread issue, but this occurs on the main thread. Either way, NSUserDefaults is documented as completely thread-safe.
This looks to me like a low-level bug in Apple's libraries. What can I do to fix this problem on my end? Who should I report it to? Has anyone else experienced a similar problem?
Thank you!

This crash has disappeared ever since upgrading Xcode to 9.4.1.

Related

Namespace SIGNAL, Code 0x5 with EXC_BREAKPOINT (SIGTRAP)

I am unable to reproduce the issue. One of my user sent the crash log and the issue seem to point to NSUserDefault setBool:forKey method.
Not working for user Device iPhone 6, iOS version: 12.4.4. For now only one user contacted due to the App crash.
Working on the devices I tested. (iPad Air 2, iPhone XS, iOS version 13.3)
This is the method I am using.
- (void) saveToDefaults:(NSString*)productId
{
[ [ NSUserDefaults standardUserDefaults ] setBool:YES forKey:productId ];
[ [ NSUserDefaults standardUserDefaults ] synchronize];
}
Crash dump
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x000000020eae32e4
Termination Signal: Trace/BPT trap: 5
Termination Reason: Namespace SIGNAL, Code 0x5
Terminating Process: exc handler [15897]
Triggered by Thread: 0
Thread 0 name:
Thread 0 Crashed:
0 CoreFoundation 0x000000020eae32e4 CFHash + 372 (CFRuntime.c:1147)
1 CoreFoundation 0x000000020eb75a38 CFBasicHashFindBucket + 224 (CFBasicHash.c:465)
2 CoreFoundation 0x000000020eb75a38 CFBasicHashFindBucket + 224 (CFBasicHash.c:465)
3 CoreFoundation 0x000000020eaada40 CFDictionaryGetValue + 120 (CFDictionary.c:413)
4 CoreFoundation 0x000000020eaca938 -[CFPrefsSearchListSource alreadylocked_setPrecopiedValues:forKeys:count:from:] + 496 (CFPrefsSearchListSource.m:632)
5 CoreFoundation 0x000000020eb81230 -[CFPrefsSource setValues:forKeys:count:copyValues:removeValuesForKeys:count:from:] + 372 (CFPrefsSource.m:742)
6 CoreFoundation 0x000000020eb81524 -[CFPrefsSource setValues:forKeys:count:copyValues:from:] + 36 (CFPrefsSource.m:766)
7 CoreFoundation 0x000000020ea3e3dc -[CFPrefsSource setValue:forKey:from:] + 64 (CFPrefsSource.m:772)
8 CoreFoundation 0x000000020eaccc54 __108-[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurat... + 272 (CFPrefsSearchListSource.m:1553)
9 CoreFoundation 0x000000020eacc698 normalizeQuintuplet + 340 (CFPrefsSearchListSource.m:63)
10 CoreFoundation 0x000000020ea3ad64 -[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurationUR... + 108 (CFPrefsSearchListSource.m:1433)
11 CoreFoundation 0x000000020ea3dd7c -[_CFXPreferences setValue:forKey:appIdentifier:container:configurationURL:] + 92 (CFXPreferences.m:759)
12 CoreFoundation 0x000000020eb8b360 _CFPreferencesSetAppValueWithContainerAndConfiguration + 132 (CFXPreferences.m:1867)
13 Foundation 0x000000020f4eb3b8 -[NSUserDefaults(NSUserDefaults) setObject:forKey:] + 64 (NSUserDefaults.m:228)
14 MyApp 0x00000001004adb14 -[IAPHelper saveToDefaults:] + 88 (IAPHelper.m:206)
15 MyApp 0x00000001004adc3c -[IAPHelper restoreTransaction:] + 224 (IAPHelper.m:223)
16 MyApp 0x00000001004ad928 -[IAPHelper paymentQueue:updatedTransactions:] + 264 (IAPHelper.m:0)
17 libdispatch.dylib 0x000000020e58ca38 _dispatch_call_block_and_release + 24 (init.c:1372)
18 libdispatch.dylib 0x000000020e58d7d4 _dispatch_client_callout + 16 (object.m:511)
19 libdispatch.dylib 0x000000020e53b008 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1068 (inline_internal.h:2441)
20 CoreFoundation 0x000000020eae0b20 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12 (CFRunLoop.c:1813)
21 CoreFoundation 0x000000020eadba58 __CFRunLoopRun + 1924 (CFRunLoop.c:3113)
22 CoreFoundation 0x000000020eadafb4 CFRunLoopRunSpecific + 436 (CFRunLoop.c:3247)
23 GraphicsServices 0x0000000210cdc79c GSEventRunModal + 104 (GSEvent.c:2245)
24 UIKitCore 0x000000023b33cc38 UIApplicationMain + 212 (UIApplication.m:4353)
25 MyApp 0x00000001004e9cec main + 88 (main.m:14)
26 libdyld.dylib 0x000000020e59e8e0 start + 4
How can I handle this exception to avoid this problem in the future.
Following up comments discussion and this answer indicating synchronize is not required (as per Apple's iOS 12 release notes):
My target iOS is from 11.2, guess I cannot use it for now.
Yes you can.
Wrapping up my suggestion in comment :
if (#available(iOS 12, *)) {
// don't need to synchronize
} else {
[NSUserDefaults.standardUserDefaults synchronize];
}
The above code #available Swift-like syntax assumes you're using Xcode 9 or higher. Which given the targeted iOS is pretty much a must.
Just to make myself 100% clear I cannot guarantee this will solve this particular crash issue, but it is worth trying as a very low effort fix candidate.

iOS Exception Backtrace - App entry not symbolicating

I have received the below exception backtrace from Apple for an app I had submitted to the app store. I have symbolicated the log but my app's entry has not symbolicated. Any idea what I can do to achieve that? Please see Entry # 14 below which provides more detail. Any help would be much appreciated
Last Exception Backtrace:
0 CoreFoundation 0x1810cadb0 __exceptionPreprocess + 124
1 libobjc.A.dylib 0x18072ff80 objc_exception_throw + 56
2 UIKit 0x186b6d268 -[UIPopoverPresentationController presentationTransitionWillBegin] + 2884
3 UIKit 0x186581fb0 __71-[UIPresentationController _initViewHierarchyForPresentationSuperview:]_block_invoke + 1640
4 UIKit 0x1865800c8 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 332
5 UIKit 0x1864d30c8 _runAfterCACommitDeferredBlocks + 292
6 UIKit 0x1864e0a80 _cleanUpAfterCAFlushAndRunDeferredBlocks + 92
7 UIKit 0x1862125a4 _afterCACommitHandler + 96
8 CoreFoundation 0x181080728 _CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
9 CoreFoundation 0x18107e4cc __CFRunLoopDoObservers + 372
10 CoreFoundation 0x18107e8fc __CFRunLoopRun + 928
11 CoreFoundation 0x180fa8c50 CFRunLoopRunSpecific + 384
12 GraphicsServices 0x182890088 GSEventRunModal + 180
13 UIKit 0x18628a088 UIApplicationMain + 204
14 MyApp 0x1000fb144 0x1000e4000 + 94532
15 libdyld.dylib 0x180b468b8 start + 4
Finally solved the problem. I was invoking UIAlertController in my code to present an action sheet with various options. To cater to devices that don't have a camera, I had added a conditional statement to directly present an ImagePicker instead of an action sheet.
iPAD testing was carried out only on the simulator which doesn't have a camera, thus directly invoking the ImagePicker. When he Conditional statement was removed, it tried presenting the Action Sheet through a PopoverPresentationController and crashed - as is evident in statement 2 of the Exception Backtrace.
I subsequently added the following code to fix the oversight:
if let popOver = optionMenu.popoverPresentationController {
popOver.sourceRect = sender.bounds
popOver.sourceView = sender
}

Weird iOS UIWebView Crash called WTF Crash

I am using UIWebViews in some of the screens, because I need a perfect Html text parsing.
According to crash reports a huge number of crashes, called WTF Crash, occur on these screens. Here is a trace of that crash
Crashed: WebThread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x00000000bbadbeef
Thread : Crashed: WebThread
0 JavaScriptCore 0x184fd2710 WTFCrash + 72
1 JavaScriptCore 0x184fd2708 WTFCrash + 64
2 WebCore 0x1852b7d78 <redacted> + 362
3 WebCore 0x1852b7bec <redacted> + 44
4 CoreFoundation 0x1817d8588 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
5 CoreFoundation 0x1817d632c __CFRunLoopDoObservers + 372
6 CoreFoundation 0x1817d6674 __CFRunLoopRun + 696
7 CoreFoundation 0x181705680 CFRunLoopRunSpecific + 384
8 WebCore 0x1852b5998 <redacted> + 456
9 libsystem_pthread.dylib 0x18148bb28 <redacted> + 156
10 libsystem_pthread.dylib 0x18148ba8c _pthread_start + 154
11 libsystem_pthread.dylib 0x181489028 thread_start + 4
There is no OS version, or device relation on this crash.
I am not doing anything fancy on using UIWebView as well. It is added to nib like every other component, and in the implementation file I use it like the following
self.webView.scrollView.scrollEnabled = NO;
self.webView.scrollView.bounces = NO;
self.webView.opaque = NO;
self.webView.backgroundColor = [UIColor clearColor];
self.webView.delegate = self;
[self.webView loadHTMLString:htmlString baseURL:nil];
Any suggestions on how to solve WTF Crash?
Edit: Here is how htmlString looks like
Printing description of htmlString:
<html><body style="font-family:HelveticaNeue; font-size:10; background-color:#E5E4E4; text-align:left; color:#696969 ">test string</body></html>
I don't know how you are creating your UIWebView. But I was having a similiar issue with a WTFCrash and I was able to solve it by making sure that the UIWebView was being created on the main thread:
- (void)createWebView{
if (![NSThread isMainThread]) {
dispatch_async(dispatch_get_main_queue(), ^{
[self createWebView];
});
return;
}
self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
//Rest of my code
}
Are you debugging your web view with Safari? If yes, the crash should be gone after you quit Safari.
I was facing a similar crash with WKWebView, and I was sure the same code worked happily 3 days ago. hlung's comments saved me, you can find it HERE.
For your reference, following is a piece of the crash log in my case.
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x00000000dbbdfb10
Triggered by Thread: 0
Filtered syslog:
None found
Thread 0 Crashed:
0 JavaScriptCore 0x225d74c6 WTF::HashSet<JSC::MarkedArgumentBuffer*, WTF::PtrHash<JSC::MarkedArgumentBuffer*>, WTF::HashTraits<JSC::MarkedArgumentBuffer*> >::remove(JSC::MarkedArgumentBuffer* const&) + 54
1 JavaScriptCore 0x22620b41 JSC::VM::~VM() + 211
2 JavaScriptCore 0x22197e57 JSC::JSLockHolder::~JSLockHolder() + 73
3 JavaScriptCore 0x2248defd JSContextGroupRelease + 61
4 JavaScriptCore 0x2250e37d -[JSVirtualMachine dealloc] + 27
5 libobjc.A.dylib 0x1dac5195 objc_object::sidetable_release(bool) + 239
6 JavaScriptCore 0x2248d261 -[JSContext dealloc] + 125
7 libobjc.A.dylib 0x1dac5195 objc_object::sidetable_release(bool) + 239
8 JavaScriptCore 0x226470af WTF::RunLoop::TimerBase::timerFired(__CFRunLoopTimer*, void*) + 25
9 CoreFoundation 0x1e807357 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 15
10 CoreFoundation 0x1e807029 __CFRunLoopDoTimer + 897
11 CoreFoundation 0x1e8069e1 __CFRunLoopDoTimers + 221
12 CoreFoundation 0x1e804cc5 __CFRunLoopRun + 1365
13 CoreFoundation 0x1e754073 CFRunLoopRunSpecific + 487
14 CoreFoundation 0x1e753e81 CFRunLoopRunInMode + 105
15 GraphicsServices 0x1ff00bfd GSEventRunModal + 157
16 UIKit 0x2390e82f -[UIApplication _run] + 575
17 UIKit 0x23908f61 UIApplicationMain + 151
18 MyApp 0x00488b29 0x2c000 + 4573993
19 libdyld.dylib 0x1df1e50b start + 3
WebKit, the engine behind Web Views, can raise a crash when it sees a memory problem.
These are identified by the special Hex Word 0x00000000bbadbeef as you have found.
The web page you are visiting seems trivial, so it is a surprise that you are having problems. I recommend you follow the WebKit debugging facilities described at:
https://webkit.org/debugging-webkit/#ios-simulator
Please update your question with any logs or insights this reveals.
It was a Google Ads issue, already fixed for sure on version 7.35.0 of October, 17 and newer versions.
You should be able to fix the issue updating your pod.
From the Google Mobile Ads SDK Developers Team mailing:
"The issue has been fixed by the team and it should go live in an upcoming SDK release (release notes)." (August, 20)
"Issue has been fixed and live already." (October, 17)
Source: https://groups.google.com/d/msg/google-admob-ads-sdk/XL35wo6mQts/R2LlGZDxBwAJ
Release Notes: https://developers.google.com/admob/ios/rel-notes

[UIThreadSafeNode createPeripheral]: unrecognized selector sent to instance

I tried to search about createPeripheral and i had no luck finding any information about it. Is there anyone here who had the same crash as this?
[UIThreadSafeNode createPeripheral]: unrecognized selector sent to instance
Which class does createPeripheral belong to?
How do you handle this crash?
note: there's not much information in the crash log
stackTrace =
(
0 CoreFoundation 0x31dcd2bb <redacted> + 186
1 libobjc.A.dylib 0x39a7297f objc_exception_throw + 30
2 CoreFoundation 0x31dd0e07 <redacted> + 170
3 CoreFoundation 0x31dcf531 <redacted> + 392
4 CoreFoundation 0x31d26f68 _CF_forwarding_prep_0 + 24
5 UIKit 0x33d4bf99 <redacted> + 52
6 UIKit 0x33bda80f <redacted> + 38
7 UIKit 0x33bda431 <redacted> + 404
8 UIKit 0x33f1ad19 <redacted> + 236
9 libdispatch.dylib 0x39e98621 <redacted> + 80
9 libdispatch.dylib 0x39e98621 <redacted> + 80
10 libdispatch.dylib 0x39e894b7 <redacted> + 22
11 libdispatch.dylib 0x39e8adcb <redacted> + 226
12 CoreFoundation 0x31da0f3b <redacted> + 1290
13 CoreFoundation 0x31d13ebd CFRunLoopRunSpecific + 356
14 CoreFoundation 0x31d13d49 CFRunLoopRunInMode + 104
15 GraphicsServices 0x358d72eb GSEventRunModal + 74
16 UIKit 0x33c29301 UIApplicationMain + 1120
...
);
Apologies for adding to an old post, but I do have a strong reproduction case for this bug. Open any software keyboard on the iPhone6+ (or iPhone6+ simulator) in a WebView. Put something in the paste-buffer, then click the paste button.
I haven't solved it yet, but I thought this might help if anyone is lost in google for this bug.
I've just got a similar crash report.
There is UIWebBrowserView in the call stack. Maybe it is a bug in it.
Our application uses UIWebView to show a simple html page, and I receive random crashes in WebView regulary. I have no idea what to do with it.
In my case this error occured when I tried to customize -inputaccessoryview on contenteditable div.
I believe createPeripheral has something to deal with Keyboard display as
webView.keyboardDisplayRequiresUserAction = NO;
solved this crash for me.

Interpreting iOS crash reports

I'm experiencing multiple crashes where it appears that a native iOS method is calling functions from a third-party library. Here's an example:
Thread: Unknown Name (Crashed)
0 libsystem_kernel.dylib 0x33222350 __pthread_kill + 8 + 8
1 libsystem_c.dylib 0x3500f973 abort + 95 + 94
2 libsystem_c.dylib 0x34ff04d1 basename + 1
3 FireChat 0x00036489 -[OTOverlayButton drawRect:] + 1
4 Foundation 0x37a4a5a9 -[NSDictionary(NSKeyValueCoding) valueForKey:] + 33 + 32
5 FireChat 0x709d -[NetworkModel getUserForUid:] (NetworkModel.m:150)
6 FireChat 0x0001c42f -[OpenTokController session:didReceiveStream:] (OpenTokController.m:258)
7 libdispatch.dylib 0x32da011f _dispatch_call_block_and_release + 11 + 10
8 libdispatch.dylib 0x32d9f4b7 _dispatch_client_callout + 23 + 22
9 libdispatch.dylib 0x32da41bd _dispatch_main_queue_callback_4CF$VARIANT$mp + 225 + 224
10 CoreFoundation 0x37dbbf3b __CFRunLoopRun + 1291 + 1290
11 CoreFoundation 0x37d2eebd CFRunLoopRunSpecific + 357 + 356
12 CoreFoundation 0x37d2ed49 CFRunLoopRunInMode + 105 + 104
13 GraphicsServices 0x358e22eb GSEventRunModal + 75 + 74
14 UIKit 0x3a1b42f9 UIApplicationMain + 1121 + 1120
15 FireChat 0x43b3 main (main.m:8)
To me, it appears that the [NSDictionary valueForKey:] method is invoking [OTOverlayButton drawRect:] which comes from a third-party library. This shouldn't be possible -- am I reading the crash report wrong?
[OTOverlayButton drawRect:] isn't called anywhere in my code. Note that the dictionary contains (my) objects which contain pointers to objects from the third-party library.
The library vendor and I are both baffled.
Thanks.
I believe the cause of this crash was memory corruption resulting from calling performSelector: on a method that returned a struct. See this blog post for more details:
Why performSelector is more dangerous than I thought

Resources