rest: reject negative sizes in HTTP response headers - fixes #10041
This commit is contained in:
1 parent
e18da08372
commit
5f0e72c03f
2 files changed
+14
-2
No files matched your search
+2
-2
@@ -165,7 +165,7 @@ func ParseSizeFromHeaders(headers http.Header) (size int64) {
|
||||
var contentLength = headers.Get("Content-Length")
|
||||
if len(contentLength) != 0 {
|
||||
var err error
|
||||
if size, err = strconv.ParseInt(contentLength, 10, 64); err != nil {
|
||||
if size, err = strconv.ParseInt(contentLength, 10, 64); err != nil || size < 0 {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
@@ -183,7 +183,7 @@ func ParseSizeFromHeaders(headers http.Header) (size int64) {
|
||||
return -1
|
||||
}
|
||||
ret, err := strconv.ParseInt(contentRange[slash+1:], 10, 64)
|
||||
if err != nil {
|
||||
if err != nil || ret < 0 {
|
||||
return -1
|
||||
}
|
||||
return ret
|
||||
|
||||
@@ -16,6 +16,12 @@ func TestParseSizeFromHeaders(t *testing.T) {
|
||||
"", "", -1,
|
||||
}, {
|
||||
"42", "", 42,
|
||||
}, {
|
||||
"0", "", 0,
|
||||
}, {
|
||||
"-5", "", -1,
|
||||
}, {
|
||||
"-5", "bytes 0-1/42", -1,
|
||||
}, {
|
||||
"42", "invalid", -1,
|
||||
}, {
|
||||
@@ -26,6 +32,12 @@ func TestParseSizeFromHeaders(t *testing.T) {
|
||||
"12", "otherUnit 22-33/42", -1,
|
||||
}, {
|
||||
"12", "bytes 22-33/*", -1,
|
||||
}, {
|
||||
"", "bytes 0-1/-5", -1,
|
||||
}, {
|
||||
"2", "bytes 0-1/-5", -1,
|
||||
}, {
|
||||
"", "bytes */0", 0,
|
||||
}, {
|
||||
"0", "bytes */42", 42,
|
||||
}}
|
||||
|
||||
Reference in new issue
Block a user