Skip to content

Commit

Permalink
Fix segfault in jody hash (#11)
Browse files Browse the repository at this point in the history
* jody: fix segfault

Segfault may be caused by buffer overflow during hash computation
on tail data.

Signed-off-by: Yerden Zhumabekov <yerden.zhumabekov@gmail.com>

* Update jody/hash.go

Co-authored-by: Achille <achille.roussel@gmail.com>
  • Loading branch information
yerden and achille-roussel committed May 27, 2020
1 parent b93db68 commit 9dc1b83
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions jody/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,22 @@ func AddString64(h uint64, s string) uint64 {
}

if n := (r.Len & 7); n != 0 {
m := mask64[n]
c := constant & m
v := *(*uint64)(p) & m // risk of segfault here?
c := constant & mask64[n]
v := uint64(0)
off := uint(0)
if 0 != (n & 4) {
v += uint64(*(*uint32)(p))
off += 32
p = unsafe.Pointer(uintptr(p) + 4)
}
if 0 != (n & 2) {
v += uint64(*(*uint16)(p)) << off
off += 16
p = unsafe.Pointer(uintptr(p) + 2)
}
if 0 != (n & 1) {
v += uint64(*(*uint8)(p)) << off
}

h = h + v + c
h = (h<<shift | h>>(64-shift)) ^ v
Expand Down

0 comments on commit 9dc1b83

Please sign in to comment.