mirror of
https://github.com/minio/minio.git
synced 2025-11-07 21:02:58 -05:00
api: Handle content-length-range policy properly. (#3297)
content-length-range policy in postPolicy API was
not working properly handle it. The reflection
strategy used has changed in recent version of Go.
Any free form interface{} of any integer is treated
as `float64` this caused a bug where content-length-range
parsing failed to provide any value.
Fixes #3295
This commit is contained in:
@@ -34,10 +34,14 @@ func toString(val interface{}) string {
|
||||
}
|
||||
|
||||
// toInteger _ Safely convert interface to integer without causing panic.
|
||||
func toInteger(val interface{}) int {
|
||||
func toInteger(val interface{}) int64 {
|
||||
switch v := val.(type) {
|
||||
case int:
|
||||
case float64:
|
||||
return int64(v)
|
||||
case int64:
|
||||
return v
|
||||
case int:
|
||||
return int64(v)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
@@ -53,8 +57,8 @@ func isString(val interface{}) bool {
|
||||
|
||||
// ContentLengthRange - policy content-length-range field.
|
||||
type contentLengthRange struct {
|
||||
Min int
|
||||
Max int
|
||||
Min int64
|
||||
Max int64
|
||||
Valid bool // If content-length-range was part of policy
|
||||
}
|
||||
|
||||
@@ -136,7 +140,11 @@ func parsePostPolicyForm(policy string) (PostPolicyForm, error) {
|
||||
Value: value,
|
||||
}
|
||||
case "content-length-range":
|
||||
parsedPolicy.Conditions.ContentLengthRange = contentLengthRange{toInteger(condt[1]), toInteger(condt[2]), true}
|
||||
parsedPolicy.Conditions.ContentLengthRange = contentLengthRange{
|
||||
Min: toInteger(condt[1]),
|
||||
Max: toInteger(condt[2]),
|
||||
Valid: true,
|
||||
}
|
||||
default:
|
||||
// Condition should be valid.
|
||||
return parsedPolicy, fmt.Errorf("Unknown type %s of conditional field value %s found in POST policy form",
|
||||
|
||||
Reference in New Issue
Block a user