App crashes in [NSJSONSerialization dataWithJSONObject:options:error:] with SIGBUS - bus error

Originator:arjun.sohaney
Number:rdar://19906886 Date Originated:20-Feb-2015 02:45 PM
Status:Open Resolved:
Product:iOS SDK Product Version:iPhone OS Version 8.1.2 (Build 12B440)
Classification:Crash Reproducible:Unable
 
Summary:
Data was read using [NSKeyedUnarchiver unarchiveObjectWithFile:] and attempted to convert to json using [NSJSONSerialization dataWithJSONObject:options:error:], the app crash with SIGBUS - bus error
{
      "StackTrace" : [
        "#2  libsystem_platform.dylib            0X383E587B _sigtramp()",
        "#3  ??                                  0X00000022 ???()",
        "#4  Foundation                          0X2AF61F15 <redacted>()",
        "#5  Foundation                          0X2AF60BAD <redacted>()",
        "#6  Foundation                          0X2AF6288D <redacted>()",
        "#7  CoreFoundation                      0X2A11A4BD <redacted>()",
        "#8  CoreFoundation                      0X2A1134F3 -[__NSArrayI enumerateObjectsWithOptions:usingBlock:]",
        "#9  Foundation                          0X2AF627D5 <redacted>()",
        "#10 Foundation                          0X2AF60D4D <redacted>()",
        "#11 Foundation                          0X2AF62963 <redacted>()",
        "#12 CoreFoundation                      0X2A162AA1 <redacted>()",
        "#13 CoreFoundation                      0X2A154BD5 -[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:]",
        "#14 Foundation                          0X2AF625E3 <redacted>()",
        "#15 Foundation                          0X2AF60D0F <redacted>()",
        "#16 Foundation                          0X2AF6288D <redacted>()",
        "#17 CoreFoundation                      0X2A11A4BD <redacted>()",
        "#18 CoreFoundation                      0X2A1134F3 -[__NSArrayI enumerateObjectsWithOptions:usingBlock:]",
        "#19 Foundation                          0X2AF627D5 <redacted>()",
        "#20 Foundation                          0X2AF60D4D <redacted>()",
        "#21 Foundation                          0X2AF6288D <redacted>()",
        "#22 CoreFoundation                      0X2A11548F <redacted>()",
        "#23 CoreFoundation                      0X2A1153B9 -[__NSArrayM enumerateObjectsWithOptions:usingBlock:]",
        "#24 Foundation                          0X2AF627D5 <redacted>()",
        "#25 Foundation                          0X2AF60D4D <redacted>()",
        "#26 Foundation                          0X2AF60B25 -[_NSJSONWriter dataWithRootObject:options:error:]",
        "#27 Foundation                          0X2AF619BF +[NSJSONSerialization dataWithJSONObject:options:error:]",        
      ]
}

Steps to Reproduce:
I have a code something like the following:
id unarchivedObj = [NSKeyedUnarchiver unarchiveObjectWithFile:someFile];
NSMutableArray *fileContents = [NSMutableArray arrayWithObject:unarchivedObj];
NSMutableArray *logData = [fileContents objectAtIndex:0];

if ([NSJSONSerialization isValidJSONObject:logData])
{
    //convert object to data
    NSData* data = [NSJSONSerialization dataWithJSONObject:logData
                                                   options:NSJSONWritingPrettyPrinted error:0];
}

It crashes in [NSJSONSerialization dataWithJSONObject:options:error:] with SIGBUS - bus error

Expected Results:
Before converting to json i am checking if a given object can be converted to json object (NSJSONSerialization isValidJSONObject:logData]) so  [NSJSONSerialization dataWithJSONObject:options:error:] shouldn't crash. It should return nil if any error occurs.

Actual Results:
The app crashes in [NSJSONSerialization dataWithJSONObject:options:error:] with SIGBUS - bus error.

Version:
iPhone OS Version 8.1.2 (Build 12B440)

Configuration:
iPad5,3

Comments

Related to Invalid type in JSON write (_NSZeroData)

Related discussion is at https://github.com/Alamofire/Alamofire/issues/1021

Also, a hitherto ungooglable error message produced by this is:

Invalid type in JSON write (_NSZeroData)

By fulldecent at Jan. 21, 2016, 6:53 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!