contenenc: reject all-zero file ID
This should never happen in normal operation and is a sign of data corruption. Catch it early.
This commit is contained in:
parent
c0e411f81d
commit
2ce269ec63
|
@ -5,6 +5,7 @@ package contentenc
|
||||||
// Format: [ "Version" uint16 big endian ] [ "Id" 16 random bytes ]
|
// Format: [ "Version" uint16 big endian ] [ "Id" 16 random bytes ]
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"log"
|
"log"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
@ -41,6 +42,9 @@ func (h *FileHeader) Pack() []byte {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// allZeroFileID is preallocated to quickly check if the data read from disk is all zero
|
||||||
|
var allZeroFileID = make([]byte, headerIDLen)
|
||||||
|
|
||||||
// ParseHeader - parse "buf" into fileHeader object
|
// ParseHeader - parse "buf" into fileHeader object
|
||||||
func ParseHeader(buf []byte) (*FileHeader, error) {
|
func ParseHeader(buf []byte) (*FileHeader, error) {
|
||||||
if len(buf) != HeaderLen {
|
if len(buf) != HeaderLen {
|
||||||
|
@ -54,6 +58,10 @@ func ParseHeader(buf []byte) (*FileHeader, error) {
|
||||||
return nil, syscall.EINVAL
|
return nil, syscall.EINVAL
|
||||||
}
|
}
|
||||||
h.ID = buf[headerVersionLen:]
|
h.ID = buf[headerVersionLen:]
|
||||||
|
if bytes.Equal(h.ID, allZeroFileID) {
|
||||||
|
tlog.Warn.Printf("ParseHeader: file id is all-zero. Returning EINVAL.")
|
||||||
|
return nil, syscall.EINVAL
|
||||||
|
}
|
||||||
return &h, nil
|
return &h, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue