move version check into newReader()

This commit is contained in:
Shubheksha Jalan 2018-01-13 00:36:20 +05:30
parent faecfac2fa
commit 618bceadb4

View file

@ -577,10 +577,6 @@ func NewReader(b ByteSlice, version int) (*Reader, error) {
// NewFileReader returns a new index reader against the given index file.
func NewFileReader(path string, version int) (*Reader, error) {
if version != 1 && version != 2 {
return nil, errors.Errorf("unexpected file version %d", version)
}
f, err := fileutil.OpenMmapFile(path)
if err != nil {
return nil, err
@ -598,6 +594,11 @@ func newReader(b ByteSlice, c io.Closer, version int) (*Reader, error) {
crc32: newCRC32(),
version: version,
}
if version != 1 && version != 2 {
return nil, errors.Errorf("unexpected file version %d", version)
}
// Verify magic number.
if b.Len() < 4 {
return nil, errors.Wrap(errInvalidSize, "index header")