Skip to content

Commit

Permalink
Merge pull request #4 from mark-rushakoff/fix-simple8b-input-panic
Browse files Browse the repository at this point in the history
Fix panic when simple8b input isn't 64-bit aligned
  • Loading branch information
jwilder committed Apr 26, 2016
2 parents b421ab4 + 52ca0fc commit ac74639
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions simple8b/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (d *Decoder) Next() bool {
d.read()
}

return len(d.bytes) > 0 || (d.i >= 0 && d.i < d.n)
return len(d.bytes) >= 8 || (d.i >= 0 && d.i < d.n)
}

func (d *Decoder) SetBytes(b []byte) {
Expand All @@ -170,7 +170,7 @@ func (d *Decoder) Read() uint64 {
}

func (d *Decoder) read() {
if len(d.bytes) == 0 {
if len(d.bytes) < 8 {
return
}

Expand Down
7 changes: 7 additions & 0 deletions simple8b/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ func Test_Encode_ValueTooLarge(t *testing.T) {
}
}

func Test_Decode_NotEnoughBytes(t *testing.T) {
dec := simple8b.NewDecoder([]byte{0})
if dec.Next() {
t.Fatalf("Expected Next to return false but it returned true")
}
}

func BenchmarkEncode(b *testing.B) {
total := 0
x := make([]uint64, 1024)
Expand Down

0 comments on commit ac74639

Please sign in to comment.