-
Notifications
You must be signed in to change notification settings - Fork 1.2k
SR-8999: NSData contentsOf expects st_size to be the size of the file. #1732
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
Conversation
- Modify FileHandle._readDataOfLength(untilEOF:options:) to ignore stat.st_size and just use the result of read() to determine whether to keep reading. - Also convert syscall error handling to throw instead of calling fatalError(). - NSData.readBytesFromFileWithExtendedAttributes(options:) now uses FileHandle._readDataOfLength(untilEOF:options:) to read from a file rather than duplicating the file reading logic. - (Linux) Add a test to read a file in /sys which reports stat.st_size > size of the file's contents.
@swift-ci test |
- readDataToEndOfFile(), readData(ofLength length: Int) and .availableData should call fataError() if there are IO errors, not return an empty Data().
Ive restored the correct behaviour. |
@swift-ci test |
1 similar comment
@swift-ci test |
|
||
let readBlockSize: Int | ||
if statbuf.st_mode & S_IFMT == S_IFREG { | ||
// TODO: Should files over a certain size always be mmap()'d? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Immediate answer: no, unless if options contains .alwaysMapped
or .mappedIfSafe
.
(I don't see .mappedIfSafe
handled here at all? Are you just assuming mapping is always unsafe? This is allowed by the contract but we should have a follow-up.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.mappedIfSafe
wasn't handled in the previous code so I haven't added it but I can do a separate PR for it.
@itaiferber @phausler If you want to chip in today, or I'll merge. |
Seems reasonable to me |
Modify FileHandle._readDataOfLength(untilEOF:options:) to ignore
stat.st_size and just use the result of read() to determine whether
to keep reading.
Also convert syscall error handling to throw instead of calling
fatalError().
NSData.readBytesFromFileWithExtendedAttributes(options:) now uses
FileHandle._readDataOfLength(untilEOF:options:) to read from a file
rather than duplicating the file reading logic.
(Linux) Add a test to read a file in /sys which reports
stat.st_size > size of the file's contents.