Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Commit

Permalink
Make sure we copy the syncMarker when reading it
Browse files Browse the repository at this point in the history
Otherwise, the syncMarker will point to the reusable array that we use for
reading.
  • Loading branch information
colinmarc committed Feb 5, 2015
1 parent 940cab7 commit eff62aa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion sequencefile/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 4 additions & 3 deletions sequencefile/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit eff62aa

Please sign in to comment.