filer: verify the media part Content-Md5 during format ingest

A supplied checksum that mismatches now rejects with BadDigest and the
uploaded chunks are deleted, matching the normal upload path.
This commit is contained in:
user.email committed 2026-10-24 09:52:12 -07:00
1 parent 291353b1e3
commit a5ac780e66
1 file changed
+8
+8
View File
@@ -26,6 +26,7 @@ import (
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
"github.com/seaweedfs/seaweedfs/weed/util"
"github.com/seaweedfs/seaweedfs/weed/util/chunk_cache"
"github.com/seaweedfs/seaweedfs/weed/util/constants"
)
const (
@@ -199,6 +200,13 @@ func (fs *FilerServer) formatIngest(ctx context.Context, w http.ResponseWriter,
writeJsonError(w, r, http.StatusInternalServerError, uploadErr)
return
}
if expectedMd5 := mediaPart.Header.Get("Content-Md5"); expectedMd5 != "" {
if md5bytes := md5Hash.Sum(nil); util.Base64Encode(md5bytes) != expectedMd5 && fmt.Sprintf("%x", md5bytes) != expectedMd5 {
cleanup()
writeJsonError(w, r, http.StatusBadRequest, errors.New(constants.ErrMsgBadDigest))
return
}
}
if total := layout.TotalSize(); written != total {
cleanup()
writeJsonError(w, r, http.StatusBadRequest, fmt.Errorf("media is %d bytes but the index describes %d", written, total))