From: Sergey Matveev Date: Sun, 3 Mar 2024 08:41:03 +0000 (+0300) Subject: Check size before hashing X-Git-Tag: v0.6.0^0 X-Git-Url: http://www.git.stargrave.org/?p=meta4ra.git;a=commitdiff_plain;h=ce902a58a32f42801603475c67dd75da86d4502a Check size before hashing --- diff --git a/cmd/meta4-check/main.go b/cmd/meta4-check/main.go index 61b5048..b807a26 100644 --- a/cmd/meta4-check/main.go +++ b/cmd/meta4-check/main.go @@ -90,6 +90,27 @@ and -extract-sig, then you can just specify empty ("") FILE. bad = true } } + + fullPath := toCheck[f.Name] + if !(len(toCheck) == 0 || fullPath != "") { + continue + } + if fullPath == "" { + fullPath = f.Name + } + s, err := os.Stat(fullPath) + if err != nil { + fmt.Println(err) + bad = true + continue + } + if uint64(s.Size()) != f.Size { + fmt.Println("size mismatch", + f.Name, "our:", s.Size(), "their:", f.Size) + bad = true + continue + } + hasher := meta4ra.NewHasher(*hashes) var hashTheir string var hashName string @@ -106,15 +127,11 @@ and -extract-sig, then you can just specify empty ("") FILE. } } } - log.Fatalln("no common hashes found for:", f.Name) + fmt.Println("no common hashes found for:", f.Name) + bad = true + continue + HashFound: - fullPath := toCheck[f.Name] - if !(len(toCheck) == 0 || fullPath != "") { - continue - } - if fullPath == "" { - fullPath = f.Name - } fd, err := os.Open(fullPath) if err != nil { fmt.Println("Error:", f.Name, err) @@ -135,7 +152,7 @@ and -extract-sig, then you can just specify empty ("") FILE. fmt.Println(f.Name, hashName, "good") } else { fmt.Println( - "Hash does not match:", f.Name, hashName, + "hash mismatch:", f.Name, hashName, "our:", hashOur, "their:", hashTheir, ) diff --git a/common.go b/common.go index 01bfa4f..5868c2c 100644 --- a/common.go +++ b/common.go @@ -17,7 +17,7 @@ package meta4ra const ( - Generator = "meta4ra/0.5.0" + Generator = "meta4ra/0.6.0" SigMediaTypePGP = "application/pgp-signature" SigMediaTypeSSH = "application/ssh-signature" )