diff options
| author | Jakob Unterwurzacher | 2017-05-25 14:20:17 +0200 | 
|---|---|---|
| committer | Jakob Unterwurzacher | 2017-05-25 14:20:27 +0200 | 
| commit | 2ce269ec63e0a9c87b2fce45a5bf0cf09abf5bba (patch) | |
| tree | 390e6917ce01a857a2ee25959fa980951da0014e /internal/contentenc | |
| parent | c0e411f81d01607fa59338365933232231738581 (diff) | |
contenenc: reject all-zero file ID
This should never happen in normal operation and is a sign of
data corruption. Catch it early.
Diffstat (limited to 'internal/contentenc')
| -rw-r--r-- | internal/contentenc/file_header.go | 8 | 
1 files changed, 8 insertions, 0 deletions
| diff --git a/internal/contentenc/file_header.go b/internal/contentenc/file_header.go index 8a08ef0..5e638ff 100644 --- a/internal/contentenc/file_header.go +++ b/internal/contentenc/file_header.go @@ -5,6 +5,7 @@ package contentenc  // Format: [ "Version" uint16 big endian ] [ "Id" 16 random bytes ]  import ( +	"bytes"  	"encoding/binary"  	"log"  	"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  func ParseHeader(buf []byte) (*FileHeader, error) {  	if len(buf) != HeaderLen { @@ -54,6 +58,10 @@ func ParseHeader(buf []byte) (*FileHeader, error) {  		return nil, syscall.EINVAL  	}  	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  } | 
