Skip to content

Commit

Permalink
fix: hash gcid empty file (#5394)
Browse files Browse the repository at this point in the history
  • Loading branch information
foxxorcat committed Oct 18, 2023
1 parent 94d0287 commit cdfbe6d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pkg/utils/hash/gcid.go
Expand Up @@ -72,11 +72,13 @@ func (h *gcid) Write(p []byte) (n int, err error) {
}

func (h *gcid) Sum(b []byte) []byte {
if hashm, ok := h.hash.(encoding.BinaryMarshaler); ok {
if hashum, ok := h.hash.(encoding.BinaryUnmarshaler); ok {
tempData, _ := hashm.MarshalBinary()
h.hash.Write(h.hashState.Sum(nil))
defer hashum.UnmarshalBinary(tempData)
if h.offset != 0 {
if hashm, ok := h.hash.(encoding.BinaryMarshaler); ok {
if hashum, ok := h.hash.(encoding.BinaryUnmarshaler); ok {
tempData, _ := hashm.MarshalBinary()
defer hashum.UnmarshalBinary(tempData)
h.hash.Write(h.hashState.Sum(nil))
}
}
}
return h.hash.Sum(b)
Expand Down

0 comments on commit cdfbe6d

Please sign in to comment.