api: xmlDecoder should honor contentLength. (#2226)

This is needed so that we avoid reading large amounts
of data from compromised clients.
This commit is contained in:
Harshavardhana
2016-07-18 21:20:17 -07:00
committed by GitHub
parent 5cc9e4e214
commit 1f706e067d
4 changed files with 68 additions and 37 deletions
+8 -2
View File
@@ -24,8 +24,14 @@ import (
)
// xmlDecoder provide decoded value in xml.
func xmlDecoder(body io.Reader, v interface{}) error {
d := xml.NewDecoder(body)
func xmlDecoder(body io.Reader, v interface{}, size int64) error {
var lbody io.Reader
if size > 0 {
lbody = io.LimitReader(body, size)
} else {
lbody = body
}
d := xml.NewDecoder(lbody)
return d.Decode(v)
}