Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KVC can corrupt NSObjects isa & return garbage. #19

Open
psineur opened this issue Jan 14, 2012 · 5 comments
Open

KVC can corrupt NSObjects isa & return garbage. #19

psineur opened this issue Jan 14, 2012 · 5 comments

Comments

@psineur
Copy link
Owner

psineur commented Jan 14, 2012

When getting struct value with memory footprint not multiple of 4 ( i.e. ccColor3B - 3 bytes) with valueForKey: via property's/method name (not via ivar name) - isa pointer can be changed (sic!).

Looks like it happens on iOS 4.3

Affected:

  • iPhone 4 with iOS 4.3.2
  • iPod Touch 4G with iOS 4.3.1
  • iPad 2 with iOS 4.3.5
  • 4.3 Simulator ( 5 bytes struct crashes, 4 bytes struct works ok)

Nonaffected:

  • iPad 2 with iOS 5.0.1
  • Mac OS X 10.7.2
  • 5.0 Simulator
psineur added a commit that referenced this issue Jan 14, 2012
psineur added a commit that referenced this issue Jan 14, 2012
@psineur
Copy link
Owner Author

psineur commented Jan 14, 2012

Update: this happens with struct like
{
GLubyte r;
GLubyte g;
GLubyte b;
}

but not with

{
GLubyte r;
GLubyte g;
GLubyte b;
GLubyte reserved1;
GLubyte reserved2;
}

Probably KVC can get struct with property/method properly only if it's size > 4 bytes.
Bigger, not bigger or equal!

@psineur
Copy link
Owner Author

psineur commented Jan 14, 2012

Update: restoring isa can help avoid crashes after using valueForKey: BUT!
value that gets returned can be garbage.

@psineur
Copy link
Owner Author

psineur commented Jan 14, 2012

Update: tested on iPad 2 with iOS 5.0.1 - works ok, bug doesn't exist. Updated first post.

@psineur
Copy link
Owner Author

psineur commented Jan 14, 2012

Update: tested on iPad 2 with iOS 4.3.5 - affected.

@psineur
Copy link
Owner Author

psineur commented Jan 14, 2012

Update: ccColor3B should be 4 bytes under 4.3 simulator to avoid KVC failure.

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

No branches or pull requests

1 participant