My favorites | Sign in
Project Home
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
Issue 86: CJsonDeserializer deserializeAsDictionary generates EXC_BAD_ACCESS (trying to append nil to a string)
2 people starred this issue and may be notified of changes. Back to list
Status:  Invalid
Owner:  ----
Closed:  Nov 2010


 
Reported by josh.petrie, Oct 23, 2010
I'm using the TouchJSON source from github, commit cfb2f51. I load the JSON in the attached "json104.txt" file into an NSData object called "data" and simply perform:

NSDictionary* graph = [[CJSONDeserializer deserializer] deserializeAsDictionary:data error:&error];

This raises EXC_BAD_ACCESS and the following stack trace:

#0	0x023364ab in CFStringGetLength
#1	0x0233868f in CFStringAppend
#2	0x0000b4d4 in -[CJSONScanner scanJSONStringConstant:error:] at CJSONScanner.m:460
#3	0x0000a1d3 in -[CJSONScanner scanJSONObject:error:] at CJSONScanner.m:147
#4	0x0000a761 in -[CJSONScanner scanJSONDictionary:error:] at CJSONScanner.m:247
#5	0x0000a22d in -[CJSONScanner scanJSONObject:error:] at CJSONScanner.m:163
#6	0x0000ad8e in -[CJSONScanner scanJSONArray:error:] at CJSONScanner.m:347
#7	0x0000a25a in -[CJSONScanner scanJSONObject:error:] at CJSONScanner.m:166
#8	0x0000a761 in -[CJSONScanner scanJSONDictionary:error:] at CJSONScanner.m:247
#9	0x00009a53 in -[CJSONDeserializer deserializeAsDictionary:error:] at CJSONDeserializer.m:108

This appears to be a regression of  issue #82 , as the JSON presented in that bug also causes this crash for me. 

json104.txt
71.2 KB   View   Download
Oct 24, 2010
#1 josh.petrie
I've narrowed it down a bit, to the following JSON:

{
    "html": "I.G.G. (Internet Gaming Gate) has announced a new 3D Hellenistic MMORPG called Gods War √جºàhttp:\/\/gw.igg.com√جºâ."
}

The issue appears to be the strange five-byte sequence that is supposed to represent a quote of some form. JSONLint is able to parse the structure as valid JSON.
Oct 24, 2010
#2 josh.petrie
I *think* the strange sequence is invalid UTF8 (which may example why [NSString initWithBytes...] fails and returns nil inside scanNotQuoteCharactersIntoString), but I'm not sure how to confirm that, nor what could be done to prevent this from crashing (the JSON is from a web service not under my control).
Oct 27, 2010
#3 josh.petrie
I've managed to avoid the problem described here by sanitizing all the input to TouchJSON. It would be more optimal of TouchJSON could do that itself when it detects an error (for example when [NSString initWithBytes] returns nil), but I can see how this may not be something that's in-line with the desired direction of the library.

So I suppose you could consider this more of a feature request at this point (implementing automatic replacement of invalid UTF8)
Oct 27, 2010
#4 josh.petrie
(I can provide the code I used to sanitize the input, but I wouldn't know for sure if its 100% correct or where the appropriate place to patch TouchJSON to use it would be).
Nov 1, 2010
Project Member #5 jwight
Bug moved to github:

http://github.com/schwa/TouchJSON/issues/issue/12
Nov 1, 2010
Project Member #6 jwight
(No comment was entered for this change.)
Status: Invalid

Powered by Google Project Hosting