mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Fix problem with sendfile(2) writing less data
When the amount of data read is more than the amount written, sendfile would not adjust 'in file' position and would resume from the wrong location. Closes #33 PiperOrigin-RevId: 196731287 Change-Id: Ia219895dd765016ed9e571fd5b366963c99afb27
This commit is contained in:
committed by
Shentubot
parent
205f1027e6
commit
9889c29d6d
@@ -1929,8 +1929,16 @@ func Sendfile(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.Sysc
|
||||
// If we don't have a provided offset.
|
||||
} else {
|
||||
// Send data using readv.
|
||||
inOff := inFile.Offset()
|
||||
r := &io.LimitedReader{R: &fs.FileReader{t, inFile}, N: count}
|
||||
n, err = io.Copy(w, r)
|
||||
inOff += n
|
||||
if inFile.Offset() != inOff {
|
||||
// Adjust file position in case more bytes were read than written.
|
||||
if _, err := inFile.Seek(t, fs.SeekSet, inOff); err != nil {
|
||||
return 0, nil, syserror.EIO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We can only pass a single file to handleIOError, so pick inFile
|
||||
|
||||
Reference in New Issue
Block a user