From 9bd1f604e8f5ad0dd33b4501c535d9915924e8bd Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Mon, 21 Sep 2015 22:39:49 +0000 Subject: [PATCH] 7329: Fix infinite loop in Compare when reading an empty file (whether or not the buf we're comparing is also empty). --- services/keepstore/volume_unix.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/services/keepstore/volume_unix.go b/services/keepstore/volume_unix.go index bc6a6e08ce..6c0f5c4e97 100644 --- a/services/keepstore/volume_unix.go +++ b/services/keepstore/volume_unix.go @@ -122,6 +122,13 @@ func (v *UnixVolume) Compare(loc string, expect []byte) error { bufLen := 1 << 20 if int64(bufLen) > stat.Size() { bufLen = int(stat.Size()) + if bufLen < 1 { + // len(buf)==0 would prevent us from handling + // empty files the same way as non-empty + // files, because reading 0 bytes at a time + // never reaches EOF. + bufLen = 1 + } } cmp := expect buf := make([]byte, bufLen) @@ -143,11 +150,6 @@ func (v *UnixVolume) Compare(loc string, expect []byte) error { return nil } else if err != nil { return err - } else if len(expect) == 0 && n == 0 && bytes.Compare(buf, expect) == 0 { - // When reading an empty block, EOF is not returned. Probably a Go issue. - // This is resulting in an infinite loop resulting in #7329 - // Handle empty block scenario explicitly until the EOF issue is resolved. - return nil } } }) -- 2.30.2