Skip to content

Commit 14038a1

Browse files
committed
fusefrontend: readFileID: reject files that consist only of a header
A header-only file will be considered empty (this is not supposed to happen). This makes File ID poisoning more difficult.
1 parent d36d53c commit 14038a1

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

internal/fusefrontend/file.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,20 @@ func (f *file) SetInode(n *nodefs.Inode) {
9191
// readFileID loads the file header from disk and extracts the file ID.
9292
// Returns io.EOF if the file is empty.
9393
func (f *file) readFileID() ([]byte, error) {
94-
buf := make([]byte, contentenc.HeaderLen)
95-
_, err := f.fd.ReadAt(buf, 0)
94+
// We read +1 byte to determine if the file has actual content
95+
// and not only the header. A header-only file will be considered empty.
96+
// This makes File ID poisoning more difficult.
97+
readLen := contentenc.HeaderLen + 1
98+
buf := make([]byte, readLen)
99+
n, err := f.fd.ReadAt(buf, 0)
96100
if err != nil {
101+
if err == io.EOF && n != 0 {
102+
tlog.Warn.Printf("ino%d: readFileID: incomplete file, got %d instead of %d bytes",
103+
f.devIno.ino, n, readLen)
104+
}
97105
return nil, err
98106
}
107+
buf = buf[:contentenc.HeaderLen]
99108
h, err := contentenc.ParseHeader(buf)
100109
if err != nil {
101110
return nil, err

0 commit comments

Comments
 (0)