From eff62aa0160980fc081755bed01f7352a5c7220c Mon Sep 17 00:00:00 2001 From: Colin Marc Date: Thu, 5 Feb 2015 02:39:58 +0100 Subject: [PATCH] Make sure we copy the syncMarker when reading it Otherwise, the syncMarker will point to the reusable array that we use for reading. --- sequencefile/header.go | 3 ++- sequencefile/reader.go | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/sequencefile/header.go b/sequencefile/header.go index e8ac9c58..ddd73bc8 100644 --- a/sequencefile/header.go +++ b/sequencefile/header.go @@ -97,7 +97,8 @@ func (r *Reader) ReadHeader() error { } r.Header.SyncMarker = string(marker) - r.syncMarkerBytes = marker + r.syncMarkerBytes = make([]byte, SyncSize) + copy(r.syncMarkerBytes, marker) return nil } diff --git a/sequencefile/reader.go b/sequencefile/reader.go index eca51d9d..2ddd7d5c 100644 --- a/sequencefile/reader.go +++ b/sequencefile/reader.go @@ -149,10 +149,11 @@ func (r *Reader) checkSyncAndScan(readValues bool) bool { // If we never read the Header, infer the sync marker from the first time we // see it. - if r.syncMarkerBytes == nil { - r.syncMarkerBytes = b + if r.syncMarkerBytes == []byte(nil) { + r.syncMarkerBytes = make([]byte, SyncSize) + copy(r.syncMarkerBytes, b) } else if !bytes.Equal(b, r.syncMarkerBytes) { - r.close(fmt.Errorf("Invalid sync marker: %x", b)) + r.close(fmt.Errorf("Invalid sync marker: %x vs %x", b, r.syncMarkerBytes)) return false }