fsck: don't misdetect a file hole at EOF

https://github.com/rfjakob/gocryptfs/issues/304 :

A second minor issue is that `if bytes.Equal(buf, allZero) {` compares the whole
buffer, although the last read could have been shorter. This could trigger the
"skip file hole" code at the end of a file although there isn't any hole to
skip.
This commit is contained in:
Jakob Unterwurzacher 2019-01-04 20:23:01 +01:00
parent 4b1d080673
commit c1a2a36a79
1 changed files with 6 additions and 3 deletions

View File

@ -153,6 +153,7 @@ func (ck *fsckObj) file(path string) {
return return
} }
defer f.Release() defer f.Release()
// 128 kiB of zeros
allZero := make([]byte, fuse.MAX_KERNEL_WRITE) allZero := make([]byte, fuse.MAX_KERNEL_WRITE)
buf := make([]byte, fuse.MAX_KERNEL_WRITE) buf := make([]byte, fuse.MAX_KERNEL_WRITE)
var off int64 var off int64
@ -167,14 +168,16 @@ func (ck *fsckObj) file(path string) {
fmt.Printf("fsck: error reading file %q (inum %d): %v\n", path, inum(f), status) fmt.Printf("fsck: error reading file %q (inum %d): %v\n", path, inum(f), status)
return return
} }
n := result.Size()
// EOF // EOF
if result.Size() == 0 { if n == 0 {
return return
} }
off += int64(result.Size()) off += int64(n)
// If we seem to be in the middle of a file hole, try to skip to the next // If we seem to be in the middle of a file hole, try to skip to the next
// data section. // data section.
if bytes.Equal(buf, allZero) { data := buf[:n]
if bytes.Equal(data, allZero) {
tlog.Debug.Printf("ck.file: trying to skip file hole\n") tlog.Debug.Printf("ck.file: trying to skip file hole\n")
f2 := f.(*fusefrontend.File) f2 := f.(*fusefrontend.File)
nextOff, err := f2.SeekData(off) nextOff, err := f2.SeekData(off)