diff options
author | Jakob Unterwurzacher | 2019-10-06 19:34:32 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2019-10-06 19:37:51 +0200 |
commit | b3c88f573f4c1b269e78dd7d1dbd6de73d477694 (patch) | |
tree | 75a898773784016015d7017ec6c3356d86aa9d08 | |
parent | 1fb18f4a9ef2bbbc6e7c774fa064808a3952bb3f (diff) |
contentenc: add explicit test for all-zero header
https://github.com/rfjakob/gocryptfs/issues/363
-rw-r--r-- | internal/contentenc/file_header.go | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/internal/contentenc/file_header.go b/internal/contentenc/file_header.go index 5f8bd63..6ce2e3b 100644 --- a/internal/contentenc/file_header.go +++ b/internal/contentenc/file_header.go @@ -44,21 +44,25 @@ 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) +var allZeroHeader = make([]byte, HeaderLen) // ParseHeader - parse "buf" into fileHeader object func ParseHeader(buf []byte) (*FileHeader, error) { if len(buf) != HeaderLen { return nil, fmt.Errorf("ParseHeader: invalid length, want=%d have=%d", HeaderLen, len(buf)) } + if bytes.Equal(buf, allZeroHeader) { + return nil, fmt.Errorf("ParseHeader: header is all-zero. Header hexdump: %s", hex.EncodeToString(buf)) + } var h FileHeader h.Version = binary.BigEndian.Uint16(buf[0:headerVersionLen]) if h.Version != CurrentVersion { - return nil, fmt.Errorf("ParseHeader: invalid version, want=%d have=%d. Hexdump: %s", + return nil, fmt.Errorf("ParseHeader: invalid version, want=%d have=%d. Header hexdump: %s", CurrentVersion, h.Version, hex.EncodeToString(buf)) } h.ID = buf[headerVersionLen:] if bytes.Equal(h.ID, allZeroFileID) { - return nil, fmt.Errorf("ParseHeader: file id is all-zero. Hexdump: %s", + return nil, fmt.Errorf("ParseHeader: file id is all-zero. Header hexdump: %s", hex.EncodeToString(buf)) } return &h, nil |