-
Notifications
You must be signed in to change notification settings - Fork 139
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
fix: file read - offset and length checks #2092
base: master
Are you sure you want to change the base?
Conversation
There is a bug that affects both reads and writes when the offset is greater than the file length; at least for the read part, it is caused by Line 455 in 26ee8dc
if ((len > 0) && (r.start + len > file_len)) . I'm not sure that would fix the write issue too, though.
|
well writes are a bit weird and would argue that nanos is more posix compliant than linux (bug) when it comes to From https://www.man7.org/linux/man-pages/man2/pwrite.2.html : that means that right now this works the same on both nanos/linux alowing you to seek and fill the "gaps" with file, err := os.OpenFile(fileName, os.O_RDWR|os.O_CREATE, 0666)
offset := fileInfo.Size() + 1 // put offset outside file length
n, err = syscall.Pwrite(int(file.Fd()), []byte("12345"), offset) but this one behaves different, on nanos behaves like the POSIX expects, but on Linux offset is not taken in consideration and data is just appended to the end of file without "gaps" file, err := os.OpenFile(fileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
offset := fileInfo.Size() + 1 // put offset outside file length
n, err = syscall.Pwrite(int(file.Fd()), []byte("12345"), offset) Is this what you are referring to about writes?
|
26b63af
to
5e48a8d
Compare
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.
Sorry, somehow I was under the impression that pwrite() was suffering from the same bug as pread(), but I checked better now and that's not the case, so pwrite() is fine as it is.
I have just 2 trivial comments on the changes for fixing pread().
- Update boundary check for file I/O completion logic - Set length to zero if starting position exceeds file length
5e48a8d
to
c8b27e6
Compare
resolve #2091