S3 api: Ignore encoding in xml body (#6953)

One user reported having discovered the following error:

API: SYSTEM()
Time: 20:06:17 UTC 12/06/2018
Error: xml: encoding "US-ASCII" declared but Decoder.CharsetReader is nil
1: cmd/handler-utils.go:43:cmd.parseLocationConstraint()
2: cmd/auth-handler.go:250:cmd.checkRequestAuthType()
3: cmd/bucket-handlers.go:411:cmd.objectAPIHandlers.PutBucketHandler()
4: cmd/api-router.go100cmd.(objectAPIHandlers).PutBucketHandler-fm()
5: net/http/server.go:1947:http.HandlerFunc.ServeHTTP()

Hence, adding support of different xml encoding. Although there
is no clear specification about it, even setting "GARBAGE" as an xml
encoding won't change the behavior of AWS, hence the encoding seems
to be ignored.

This commit will follow that behavior and will ignore encoding field
and consider all xml as utf8 encoded.
master
Anis Elleuch 6 years ago committed by kannappanr
parent 48cb0ea34b
commit 50f6f9fe58
  1. 8
      cmd/utils.go

@ -105,6 +105,12 @@ const (
httpsScheme = "https" httpsScheme = "https"
) )
// nopCharsetConverter is a dummy charset convert which just copies input to output,
// it is used to ignore custom encoding charset in S3 XML body.
func nopCharsetConverter(label string, input io.Reader) (io.Reader, error) {
return input, nil
}
// xmlDecoder provide decoded value in xml. // xmlDecoder provide decoded value in xml.
func xmlDecoder(body io.Reader, v interface{}, size int64) error { func xmlDecoder(body io.Reader, v interface{}, size int64) error {
var lbody io.Reader var lbody io.Reader
@ -114,6 +120,8 @@ func xmlDecoder(body io.Reader, v interface{}, size int64) error {
lbody = body lbody = body
} }
d := xml.NewDecoder(lbody) d := xml.NewDecoder(lbody)
// Ignore any encoding set in the XML body
d.CharsetReader = nopCharsetConverter
return d.Decode(v) return d.Decode(v)
} }

Loading…
Cancel
Save