allen58992008 / touchcode

Automatically exported from code.google.com/p/touchcode
0 stars 0 forks source link

CJsonDeserializer deserializeAsDictionary generates EXC_BAD_ACCESS (trying to append nil to a string) #86

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
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. 

Original issue reported on code.google.com by josh.petrie on 24 Oct 2010 at 4:28

Attachments:

GoogleCodeExporter commented 8 years ago
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.

Original comment by josh.petrie on 24 Oct 2010 at 7:09

GoogleCodeExporter commented 8 years ago
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).

Original comment by josh.petrie on 24 Oct 2010 at 7:44

GoogleCodeExporter commented 8 years ago
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)

Original comment by josh.petrie on 27 Oct 2010 at 3:18

GoogleCodeExporter commented 8 years ago
(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).

Original comment by josh.petrie on 27 Oct 2010 at 3:19

GoogleCodeExporter commented 8 years ago
Bug moved to github:

http://github.com/schwa/TouchJSON/issues/issue/12

Original comment by jwight on 1 Nov 2010 at 6:48

GoogleCodeExporter commented 8 years ago

Original comment by jwight on 1 Nov 2010 at 7:31