mirror of
https://github.com/minio/minio.git
synced 2025-11-20 09:56:07 -05:00
Return errors in PutObject()/PutObjectPart() if input size is -1. (#5015)
Amazon S3 API expects all incoming stream has a content-length set it was superflous for us to support object layer which supports unknown sized stream as well, this PR removes such requirements and explicitly error out if input stream is less than zero.
This commit is contained in:
committed by
Dee Koder
parent
d1712a46a7
commit
0b546ddfd4
@@ -382,35 +382,37 @@ func evalDisks(disks []StorageAPI, errs []error) []StorageAPI {
|
||||
return newDisks
|
||||
}
|
||||
|
||||
// Errors specifically generated by getPartSizeFromIdx function.
|
||||
// Errors specifically generated by calculatePartSizeFromIdx function.
|
||||
var (
|
||||
errPartSizeZero = errors.New("Part size cannot be zero")
|
||||
errPartSizeIndex = errors.New("Part index cannot be smaller than 1")
|
||||
)
|
||||
|
||||
// getPartSizeFromIdx predicts the part size according to its index. It also
|
||||
// returns -1 when totalSize is -1.
|
||||
func getPartSizeFromIdx(totalSize int64, partSize int64, partIndex int) (int64, error) {
|
||||
// calculatePartSizeFromIdx calculates the part size according to input index.
|
||||
// returns error if totalSize is -1, partSize is 0, partIndex is 0.
|
||||
func calculatePartSizeFromIdx(totalSize int64, partSize int64, partIndex int) (currPartSize int64, err error) {
|
||||
if totalSize < 0 {
|
||||
return 0, traceError(errInvalidArgument)
|
||||
}
|
||||
if partSize == 0 {
|
||||
return 0, traceError(errPartSizeZero)
|
||||
}
|
||||
if partIndex < 1 {
|
||||
return 0, traceError(errPartSizeIndex)
|
||||
}
|
||||
switch totalSize {
|
||||
case -1, 0:
|
||||
return totalSize, nil
|
||||
}
|
||||
// Compute the total count of parts
|
||||
partsCount := totalSize/partSize + 1
|
||||
// Return the part's size
|
||||
switch {
|
||||
case int64(partIndex) < partsCount:
|
||||
return partSize, nil
|
||||
case int64(partIndex) == partsCount:
|
||||
// Size of last part
|
||||
return totalSize % partSize, nil
|
||||
default:
|
||||
return 0, nil
|
||||
if totalSize > 0 {
|
||||
// Compute the total count of parts
|
||||
partsCount := totalSize/partSize + 1
|
||||
// Return the part's size
|
||||
switch {
|
||||
case int64(partIndex) < partsCount:
|
||||
currPartSize = partSize
|
||||
case int64(partIndex) == partsCount:
|
||||
// Size of last part
|
||||
currPartSize = totalSize % partSize
|
||||
default:
|
||||
currPartSize = 0
|
||||
}
|
||||
}
|
||||
return currPartSize, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user