fix: s3-check-md5 to not panic for incomplete md5

This commit is contained in:
Harshavardhana 2022-05-30 20:58:10 -07:00
parent 56a61bab56
commit befbf48563

View File

@ -127,7 +127,7 @@ func main() {
// List all objects from a bucket-name with a matching prefix.
for object := range s3Client.ListObjects(context.Background(), bucket, opts) {
if object.Err != nil {
log.Fatalln("LIST error:", object.Err)
log.Println("LIST error:", object.Err)
continue
}
if object.IsDeleteMarker {
@ -162,6 +162,7 @@ func main() {
}
var partsMD5Sum [][]byte
var failedMD5 bool
for p := 1; p <= parts; p++ {
opts := minio.GetObjectOptions{
VersionID: object.VersionID,
@ -170,16 +171,23 @@ func main() {
obj, err := s3Client.GetObject(context.Background(), bucket, object.Key, opts)
if err != nil {
log.Println("GET", bucket, object.Key, object.VersionID, "=>", err)
continue
failedMD5 = true
break
}
h := md5.New()
if _, err := io.Copy(h, obj); err != nil {
log.Println("MD5 calculation error:", bucket, object.Key, object.VersionID, "=>", err)
continue
failedMD5 = true
break
}
partsMD5Sum = append(partsMD5Sum, h.Sum(nil))
}
if failedMD5 {
log.Println("CORRUPTED object:", bucket, object.Key, object.VersionID)
continue
}
corrupted := false
if !multipart {
md5sum := fmt.Sprintf("%x", partsMD5Sum[0])