Skip to content
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

fs.read into zero buffer should not throw exception #4517

Closed
feross opened this issue Jan 3, 2016 · 1 comment
Closed

fs.read into zero buffer should not throw exception #4517

feross opened this issue Jan 3, 2016 · 1 comment
Labels
fs Issues and PRs related to the fs subsystem / file system.

Comments

@feross
Copy link
Contributor

feross commented Jan 3, 2016

Given a file descriptor fd that references a non-zero-length file, I expect this code to work:

var buf = new Buffer(0)
// Read zero bytes into offset 0 of `buf`
fs.read(fd, buf, 0, 0, 0, function(err, bytesRead, buffer) {
  console.log('got buffer', buffer)
}

Instead it throws an exception because it assumes that offset is out bounds because it starts at the end of the buffer (based on the buffer's length). If length was a positive number, this would be out of bounds. But when length is 0, an offset that starts at the end of the buffer is fine.

I expect a buffer of length zero to be returned in the callback, with no error, and no thrown exception.

@feross
Copy link
Contributor Author

feross commented Jan 3, 2016

Sent a PR that fixes the issue: #4518

@mscdex mscdex added the fs Issues and PRs related to the fs subsystem / file system. label Jan 3, 2016
@jasnell jasnell closed this as completed Jan 6, 2016
jasnell pushed a commit that referenced this issue Jan 6, 2016
Fixes: #4517.
PR-URL: #4518
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
scovetta pushed a commit to scovetta/node that referenced this issue Apr 2, 2016
Fixes: nodejs#4517.
PR-URL: nodejs#4518
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

No branches or pull requests

2 participants