Crashes in encodeArrayForAPI: and convertFoundationTypesToJSON: under iOS 13
Closed this issue · 2 comments
PavelGnatyuk commented
Integration Method: CocoaPods
Xcode Version: Xcode 11.6
Library Version:
Platform: iOS
Language: Objective-C
Description:
Expected Behavior:
Crash happens in the encodeArrayAsJSONData call or inside it in encodeArrayAsJSONData (exactly in the conversion to JSON):
+ (NSString *)encodeArrayForAPI:(NSArray *)array {
NSData *data = [MPNetwork encodeArrayAsJSONData:array]; // Crash in this line. EXC_BAD_ACCESS KERN_INVALID_ADDRESS
return [MPNetwork encodeJSONDataAsBase64:data];
}
+ (NSData *)encodeArrayAsJSONData:(NSArray *)array {
NSError *error = NULL;
NSData *data = nil;
@try {
data = [NSJSONSerialization dataWithJSONObject:[self convertFoundationTypesToJSON:array]
options:(NSJSONWritingOptions)0
error:&error]; //crash in this line EXC_BAD_ACCESS KERN_INVALID_ADDRESS
}
@catch (NSException *exception) {
MPLogError(@"exception encoding api data: %@", exception);
}
if (error) {
MPLogError(@"error encoding api data: %@", error);
}
return data;
}
zihejia commented
hi @PavelGnatyuk , I'm very sorry for the late response. Could you provide more information? This will help us a lot for narrowing it down.
- Do you have a full crash log showing all threads?
- Did it happen only in iOS 13, what is the percentage of the crash if you have the data?
- Do you use crashlytics, do you see any other error logs?
- Any chance you can reproduce it?
- which SDK version you are using.
- Any other information you'd like to share would be super helpful.
In the meantime, I'm thinking of two possible causes for this crash but need more information to deep dive further.
- It might related to the iOS 13 bug for
encodeArrayAsJSONData:
if the inputarray
inencodeArrayAsJSONData:(NSArray *)array
contains corrupted characters(not valid UTF-8), see radar https://openradar.appspot.com/radar?id=4964054569320448 (NSJSONSerialization crashes on iOS 13) - There is a race condition in the input
array
accessed by other threads trying to mutating it.
zihejia commented
It has been fixed in v3.6.3