From 962bc7df4e932e051803d5fa46a2f9863e6e98a4 Mon Sep 17 00:00:00 2001 From: WithoutPants <53250216+WithoutPants@users.noreply.github.com> Date: Tue, 8 Nov 2022 10:01:32 +1100 Subject: [PATCH] Fix panic when fileSize is negative (#3089) --- pkg/hash/oshash/oshash.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/hash/oshash/oshash.go b/pkg/hash/oshash/oshash.go index 7d0687b99..2c42afd2a 100644 --- a/pkg/hash/oshash/oshash.go +++ b/pkg/hash/oshash/oshash.go @@ -48,8 +48,8 @@ func oshash(size int64, head []byte, tail []byte) (string, error) { // FromFilePath calculates the hash reading from src. func FromReader(src io.ReadSeeker, fileSize int64) (string, error) { - if fileSize == 0 { - return "", nil + if fileSize <= 0 { + return "", fmt.Errorf("cannot calculate oshash for empty file (size %d)", fileSize) } fileChunkSize := chunkSize