From 801513fb75d02d3f9dc898e13af602f49aa9fe42 Mon Sep 17 00:00:00 2001 From: Ben Boyter Date: Mon, 5 Jan 2026 18:14:24 +1100 Subject: [PATCH] patch issue --- vendor/go.felesatra.moe/hash/ed2k/ed2k.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/vendor/go.felesatra.moe/hash/ed2k/ed2k.go b/vendor/go.felesatra.moe/hash/ed2k/ed2k.go index df22fb7..acbf8d9 100644 --- a/vendor/go.felesatra.moe/hash/ed2k/ed2k.go +++ b/vendor/go.felesatra.moe/hash/ed2k/ed2k.go @@ -76,12 +76,22 @@ func (h *Hash) limitNextChunk(b []byte) []byte { // Sum appends the current hash to b and returns the resulting slice. // It does not change the underlying hash state. func (h *Hash) Sum(b []byte) []byte { - if h.written < ChunkSize { + if h.written == 0 { return h.subhash.Sum(b) } - if h.written == ChunkSize { + + // If there's an uncommitted chunk, hash it and add to the hashlist + if h.written%ChunkSize != 0 { + h.hashlist = h.subhash.Sum(h.hashlist) + } + + // If the total written data is less than or equal to one chunk, + // the hashlist already contains the final hash (or the hash of the single chunk). + if h.written <= ChunkSize { return append(b, h.hashlist...) } + + // For multiple chunks, hash the hashlist itself. h2 := md4.New() h2.Write(h.hashlist) return h2.Sum(b)