Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSJSONSerialization bug?

Been trying to debug a crash for the past 10 hours and finally, I simplified it to this code:

NSError *error = nil;
NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"payload" ofType:@"txt"]];
id obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];

With NSZombieEnabled, this crashes the app at the third line (where the parsing happens) and it logs:

*** -[CFString retain]: message sent to deallocated instance 0x758afa0

The contents of payload.txt are:

[
   {
      "created_at":"2013-02-15T23:46:02-05:00",
      "description":"Take out the Big Gun sounded simple enough, except the Strogg were waiting. You, and a few marines like you, are the lucky ones. You've made it down in one piece and are still able to contact the fleet. The Gravity Well, the Strogg's newest weapon in its arsenal against mankind, is operational. With the fleet around Stroggos, 5% of ground forces surviving, and that number dwindling by the second, your orders have changed: free your comrades. Destroy the Gravity Well.Minimum: A 100% Windows XP/Vista-compatible computer system",
      "developer":"id Software",
      "external_id":"2340",
      "id":745,
      "image":"http://cdn.steampowered.com/v/gfx/apps/2340/header_292x136.jpg",
      "is_subscribed":0,
      "link":"http://store.steampowered.com/app/2340/",
      "price":"4.99",
      "seller_id":2,
      "thumb":"http://media.steampowered.com/steamcommunity/public/images/apps/2340/5bd6e22ffdf72fdfb5ce2092fa50150de5fbb56f.jpg",
      "title":"Quake II: Ground Zero",
      "updated_at":"2013-02-15T23:46:02-05:00",
      "is_subscribed":0
   },
   {
      "created_at":"2013-02-15T23:45:59-05:00",
      "description":"Rage through 32 single player levels and 6 deathmatch levels of sheer terror and fully immersive sound and lighting. Arm yourself against the cannibalistic Ogre, fiendish Vore and indestructible Schambler using lethal nails, fierce Thunderbolts and abominable Rocket and Grenade Launchers.Minimum: A 100% Windows XP/Vista-compatible computer system",
      "developer":"id Software",
      "external_id":"2310",
      "id":742,
      "image":"http://cdn.steampowered.com/v/gfx/apps/2310/header_292x136.jpg",
      "is_subscribed":0,
      "link":"http://store.steampowered.com/app/2310/",
      "price":"9.99",
      "seller_id":2,
      "thumb":"http://media.steampowered.com/steamcommunity/public/images/apps/2310/e5bdf8dc7759c573fe525d45b69011f6a173a984.jpg",
      "title":"Quake",
      "updated_at":"2013-02-15T23:45:59-05:00",
      "is_subscribed":0
   }
]

It's just an array of 2 dictionaries. I am not sure what's causing this crash/what's wrong with this JSON.

UPDATE Removing "is_subscribed":0 in the first object in the array gets rid of the crash.

like image 545
0xSina Avatar asked Feb 16 '13 10:02

0xSina


2 Answers

It looks like Apple did a bad work in error handling of such cases within their class, since your getting crash instead of normal nil result and error variable populated. Your json data and minimalistic code is what Apple usually require for a proper bug report. Report the bug by following link - https://developer.apple.com/bugreporter/ do not forget to attach project in zip as a proof that it crashes.

like image 175
Nikita Leonov Avatar answered Sep 30 '22 16:09

Nikita Leonov


I had this issue and for me, the issue was a duplicate key in the JSON. My key was named differently - not "is_subscribed" like in your case, but "food_nutrients". I'm willing to bet that iOS 6 crashes on any duplicate keys where there's another key in between - not just an "is_subscribed" key as some of the comments suggest.

I've confirmed that duplicate keys of any name are the issue. Related: https://stackoverflow.com/a/21148319/2030

like image 34
Josh Brown Avatar answered Sep 30 '22 14:09

Josh Brown