NSData data corrupts if destroy source NSData
| Originator: | aironik | ||
| Number: | rdar://14175384 | Date Originated: | 2013-03-17 |
| Status: | Resolved: | ||
| Product: | iOS SDK | Product Version: | 7.0 beta 1 |
| Classification: | Serious Bug | Reproducible: |
Summary: -[NSData data] bytes value changes if source NSData object destroys.
Steps to Reproduce:
__strong NSData *dataRes = nil;
@autoreleasepool {
// Create NSData:
NSString *string = @"Some Data";
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
// data contains <536f6d65 20446174 61>
// create new NSData object without copy
NSData *data2 = [NSData dataWithBytesNoCopy:data.bytes length:[data length] freeWhenDone:NO];
// data2 contains <536f6d65 20446174 61>
// copy data object
dataRes = [data2 copy]; // same result for dataRes = [NSData dataWithData:data2];
// dataRes contains <536f6d65 20446174 61>
} // destroy source data object
// here dataRes contains other data e.g. <00000090 97868e20 61>
Expected Results:
data doesn't change value. For above example <536f6d65 20446174 61>
Actual Results:
data changes bytes value.
Regression:
occurs iOS7 beta 1
Notes:
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!
Will probably be closed as behaves correctly
While I'm not sure about -copy, +dataWithData: is definitely a shallow copy. CFDataCreateCopy doesn't create a copy of the bytes if the source was immutable; I imagine NSData -copy doesn't either