Skip to content

Commit

Permalink
Make value retrieval not panic
Browse files Browse the repository at this point in the history
  • Loading branch information
calebcase committed Dec 16, 2021
1 parent 604174c commit 38c5a6c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ func (b *block) Xor(other *block) {
func (b *block) Value() []byte {
size := binary.BigEndian.Uint64(b.Data[:8])

// This truncates the value. The user of value should be comparing it
// to the value hash (done elsewhere) and that will (usually) catch
// this error.
if 8+size > uint64(len(b.Data)) {
size = uint64(len(b.Data)) - 8
}

return b.Data[8 : 8+size]
}

Expand Down

0 comments on commit 38c5a6c

Please sign in to comment.