mirror of
https://github.com/distribution/distribution.git
synced 2025-06-28 16:27:06 +00:00
Enable MD5 check on GCS driver (#4586)
This commit is contained in:
commit
1b01625dae
@ -14,6 +14,7 @@ package gcs
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/md5"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -425,6 +426,14 @@ func (d *driver) putContent(ctx context.Context, obj *storage.ObjectHandle, cont
|
|||||||
if _, err := bytes.NewReader(content).WriteTo(wc); err != nil {
|
if _, err := bytes.NewReader(content).WriteTo(wc); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// NOTE(milosgajdos): Apparently it's posisble to to upload 0-byte content to GCS.
|
||||||
|
// Setting MD5 on the Writer helps to prevent presisting that data.
|
||||||
|
// If set, the uploaded data is rejected if its MD5 hash does not match this field.
|
||||||
|
// See: https://pkg.go.dev/cloud.google.com/go/storage#ObjectAttrs
|
||||||
|
h := md5.New()
|
||||||
|
h.Write(content)
|
||||||
|
wc.MD5 = h.Sum(nil)
|
||||||
|
|
||||||
return wc.Close()
|
return wc.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user