Skip to content

Instantly share code, notes, and snippets.

@Raztor0
Last active March 3, 2018 23:47
Show Gist options
  • Save Raztor0/e96f54bb522aa4ad2a8b5b84ef94b0b9 to your computer and use it in GitHub Desktop.
Save Raztor0/e96f54bb522aa4ad2a8b5b84ef94b0b9 to your computer and use it in GitHub Desktop.
NSJSONSerialization EXC_BAD_ACCESS KERN_INVALID_ADDRESS
+ (void)load {
static NSMutableDictionary *myMutableDict;
static NSDictionary *myDict;
myMutableDict = [NSMutableDictionary dictionaryWithDictionary:@{}];
myDict = @{@"sub_dict" : myMutableDict};
/* Hop on a background thread */
dispatch_async(dispatch_get_global_queue(0, 0), ^{
/* Constantly mutate the mutable dictionary */
while (YES) {
[myMutableDict setObject:[[NSUUID UUID] UUIDString] forKey:[[NSUUID UUID] UUIDString]];
}
});
while (YES) {
/* Constantly try serializing the non-mutable outer dictionary */
/* This line will eventually result in EXC_BAD_ACCESS KERN_INVALID_ADDRESS */
NSData * __unused data = [NSJSONSerialization dataWithJSONObject:myDict options:kNilOptions error:nil];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment