File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff 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.
9393func (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
You can’t perform that action at this time.
0 commit comments