Cannot serialize integers in Mac OS X 10.7 #15

Closed
andypotion opened this Issue Apr 8, 2011 · 9 comments

Projects

None yet

5 participants

@andypotion

The following code will crash in Mac OS X Lion Developer Preview 2:

[[NSArray arrayWithObject:[NSNumber numberWithInteger:1]] JSONString]

The crash happens when you try to get the isa value for the number object because they seem to be optimized special pointers in the runtime now.

@johnezang
Owner

After working with Andy on this bug (thanks @andypotion!), we were able to determine the cause of the problem.

However, since this is a bug that is specific to Mac OS X 10.7 / Lion, there are various NDA issues involved in discussing the problem publicly.

A work-around is known, but there's a legitimate question as to whether or not this is a bug in JSONKit or not. It's not clear if the work around should be checked in or if the problem should be resolved "up stream" from JSONKit, so to speak.

@johnezang
Owner

This is likely a duplicate of issue #9.

@johnezang johnezang was assigned May 21, 2011
@snej
snej commented Jul 17, 2011

JSONKit is groping into an NSNumber object to dereference the 'isa' field. As far as I know this is not kosher since it makes assumptions about object memory layout that Apple could change in future OS versions, including Lion. I don't think you can assign blame upstream to Foundation.

This is probably faster than using the Obj-C runtime API to look up the class, but I don't think you can continue to do it, at least not in these hypothetical future OS versions/configurations where Apple may or may not have changed the layout of certain objects. You might need to use #ifdefs to fall back to safer, if slower, techniques.

@snej
snej commented Jul 22, 2011

Now that Lion is no longer under NDA, could someone please post the workaround as a patch?

@hiltonc
hiltonc commented Jul 22, 2011

I'm also running into this problem. Anyone have a fix?

@snej
snej commented Jul 22, 2011

My current workaround is to use NSJSONSerialization instead, when it's available. I do a runtime check to look up the class by name, and then call it if it's there instead of JSONKit.

@0xced
0xced commented Jul 23, 2011

I guess that Tagged pointers and fast-pathed CFNumber integers in Lion is the cause of this problem.

@andypotion

I just submitted a pull request for this. People needing the fix ASAP should check out my fork.

@johnezang johnezang added a commit that referenced this issue Sep 23, 2011
@johnezang Fixes issues #9, #15, #40, aka "crashes on 64-bit Lion / 10.7 ABI".
This commit implements a work around for a bug in 10.7 that was caused by
a 10.7 64-bit ABI breaking change.

Technically, this is not a bug in JSONKit, but with Mac OS X.

When making changes to the ABI, it is (at least de facto) required to bump
the "major version" of a shared library so that code designed around and
built against the "guarantees" provided by previous versions ABI / API
are not violated.

Not only was this not done in 10.7, the ABI breaking change isn't even
officially documented (to the best of my knowledge).  It's certainly not
mentioned in the 10.7 release notes.
c2ef692
@johnezang johnezang closed this Sep 23, 2011
@johnezang
Owner

Fixed in commit johnezang/JSONKit@c2ef692.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment