NSDataReadingMappedAlways fails on iOS 7
| Originator: | earltedly | ||
| Number: | rdar://14388203 | Date Originated: | 09-Jul-2013 01:51 PM |
| Status: | Open | Resolved: | |
| Product: | iPhone/iPod touch | Product Version: | 7.0 (11A4414e) |
| Classification: | UI/Usability | Reproducible: | Always |
Summary:
When memory mapping a file of 305mb on iOS 7 using NSData or directly with mmap the operation will fail.
Steps to Reproduce:
Via NSData:
NSString* dataFileName = @"path to 305mb file on the device";
NSError *error = nil;
NSData *data = [NSData dataWithContentsOfFile:dataFileName options:NSDataReadingMappedAlways error:&error];
Expected Results:
A pointer to an NSData object with the mapped data.
Actual Results:
A nil pointer and the following error:
Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)" UserInfo=0x1640f910 {NSFilePath=/var/mobile/Applications/BED90A40-2303-4C4B-A4A3-E60D627A96B4/theapp.app/dataFile.blob, NSUnderlyingError=0x1640f5b0 "The operation couldn’t be completed. Cannot allocate memory"}
Regression:
This has been reproduced on an iPhone 4, but not on an iPhone 5. Both running iOS 7 beta 3. All devices are able to map the file on iOS 6.
Notes:
The following code will also fail on the iPhone 4:
- (NSData*)manuallyMapFile:(NSString*)file
{
int fd = open([file fileSystemRepresentation], O_RDONLY);
if(fd < 0)
{
return nil;
}
NSDictionary* attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:file error:nil];
if(attributes == nil)
{
close(fd);
return nil;
}
self.size = [attributes objectForKey:NSFileSize];
_mappedPointer = mmap(0, [_size intValue], PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0);
close(fd);
if(_mappedPointer == MAP_FAILED)
{
DDLogError(@"Map failed, errno=%d, %s", errno, strerror(errno));
_mappedPointer = NULL;
return nil;
}
NSData* retVal = [NSData dataWithBytesNoCopy:_mappedPointer length:[_size intValue] freeWhenDone:NO];
return retVal;
}
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!