NSKeyedArchiver does not correctly preserve CGPoints with INFINITY values

Originator:matej
Number:rdar://20224363 Date Originated:19-Mar-2015 05:34 PM
Status:Open Resolved:
Product:iOS Product Version:8.2
Classification:Serious Bug Reproducible:Always
 
Summary:
Using encodeCGPoint: forKey: and decodeCGPointForKey: to first encode and later decode a CGPoint with the value of CGPointMake(INFINITY, INFINITY) produces a point with the x and y value set to 0, instead of to INFINITY.

Steps to Reproduce:
Open the attached sample project and run the tests target. 

Expected Results:
The decoded CGPoint would have it’s x and y components set to INFINITY, matching the original.

Actual Results:
The decoded CGPoint has it’s x and y components set to 0, IN CONTRAST WITH the original.

Regression:
Tested on iOS 8 and iOS 7 simulator as well as on an iPhone 6 with iOS 8.2.

Notes:
Encoding a CGFloat with encodeDouble:forKey: and decoding with decodeDoubleForKey: works as expected for INFINITY values.

Comments

Workaround

To work around this we can make use of (CoreFoundation) dictionary representation of CGPoints. Apparently, it's just UIKit's geometry extensions that are broken (both NSValue (NSValueUIGeometryExtensions) extension and NSCoder (UIGeometryKeyedCoding)). https://gist.github.com/vendruscolo/e0904f9054e0d42f29c2

By alessandro.vendruscolo at March 20, 2015, 4:52 p.m. (reply...)

Test output

InfCGPointSerializationSampleTests.m: test failure: -[InfCGPointSerializationSampleTests testInf] failed: ((CGPointEqualToPoint(point.point, newPoint.point)) is true) failed - The original and de-serialized points do not match. Original: - number: inf point: {inf, inf} De-serialized: - number: inf point: {0, 0}

Sample project

http://cl.ly/2d0q1Z0J3W2K


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!