Skip to content

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

Merged
merged 2 commits into from
Oct 23, 2018

Conversation

spevans
Copy link
Contributor

@spevans spevans commented Oct 20, 2018

  • 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.

- 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.
@spevans
Copy link
Contributor Author

spevans commented Oct 20, 2018

@swift-ci test

- readDataToEndOfFile(), readData(ofLength length: Int) and
  .availableData should call fataError() if there are IO errors,
  not return an empty Data().
@spevans
Copy link
Contributor Author

spevans commented Oct 20, 2018

Ive restored the correct behaviour.

@spevans
Copy link
Contributor Author

spevans commented Oct 20, 2018

@swift-ci test

1 similar comment
@spevans
Copy link
Contributor Author

spevans commented Oct 21, 2018

@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?
Copy link
Contributor

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.)

Copy link
Contributor Author

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.

@millenomi
Copy link
Contributor

@itaiferber @phausler If you want to chip in today, or I'll merge.

@phausler
Copy link
Contributor

Seems reasonable to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants