Exit tmpfs.fileInodeOperations.Translate early if required.Start >= EOF.

Otherwise required and optional can be empty or have negative length.

PiperOrigin-RevId: 204007079
Change-Id: I59e472a87a8caac11ffb9a914b8d79bf0cd70995
This commit is contained in:
Jamie Liu
2018-07-10 13:58:54 -07:00
committed by Shentubot
parent bf580cf64d
commit 06920b3d1b
+10 -4
View File
@@ -451,9 +451,12 @@ func (f *fileInodeOperations) Translate(ctx context.Context, required, optional
// Constrain translations to f.attr.Unstable.Size (rounded up) to prevent
// translation to pages that may be concurrently truncated.
pgend := fs.OffsetPageEnd(f.attr.Unstable.Size)
var buserr error
var beyondEOF bool
if required.End > pgend {
buserr = &memmap.BusError{io.EOF}
if required.Start >= pgend {
return nil, &memmap.BusError{io.EOF}
}
beyondEOF = true
required.End = pgend
}
if optional.End > pgend {
@@ -481,9 +484,12 @@ func (f *fileInodeOperations) Translate(ctx context.Context, required, optional
// Don't return the error returned by f.data.Fill if it occurred outside of
// required.
if translatedEnd < required.End && cerr != nil {
return ts, cerr
return ts, &memmap.BusError{cerr}
}
return ts, buserr
if beyondEOF {
return ts, &memmap.BusError{io.EOF}
}
return ts, nil
}
// InvalidateUnsavable implements memmap.Mappable.InvalidateUnsavable.