Parsing JSON containing large numbers results in data loss when converting from NSNumber to scalar integer types
| Originator: | jeremy | ||
| Number: | rdar://15723600 | Date Originated: | 2013-12-24 |
| Status: | Dupe | Resolved: | 2014-01-09 |
| Product: | iOS | Product Version: | 7.0 |
| Classification: | Data loss | Reproducible: | Always |
Summary:
When reading a JSON feed from a remote server, and serializing the data to a dictionary, and printing the result shows the lower ~10 bits of the scalar type set to 0, thus resulting in data loss when printing out the integer.
Steps to Reproduce:
1. Run the attached test case
Expected Results:
I would expect to see printed:
6988047877858960833 6988047877858960833
Actual Results:
I see printed:
6988047877858960833 6988047877858960384
Version:
iOS 7.0.3/iPhone 5
Notes:
Parsing the NSNumber is sufficient to reveal this bug.
Configuration:
Occurs on iOS 7, on iPhone 5 & 5S as well as in 32-bit and 64-bit simulators.
Attachments:
'nsnumber-corruption.m' was successfully uploaded.
#import <Foundation/Foundation.h>
int main(void)
{
@autoreleasepool {
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:[@"{\"id\":6988047877858960833}" dataUsingEncoding:NSUTF8StringEncoding] options:0 error:NULL];
NSLog(@"%@ %llu", json[@"id"], [json[@"id"] unsignedLongLongValue]);
}
return 0;
}
Comments
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!