From 50f6f9fe58332274d6a3e36072f0e8f25df5fc70 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Thu, 13 Dec 2018 21:09:50 +0100 Subject: [PATCH] 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. --- cmd/utils.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/utils.go b/cmd/utils.go index 956822a80..a577c23ff 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -105,6 +105,12 @@ const ( 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. func xmlDecoder(body io.Reader, v interface{}, size int64) error { var lbody io.Reader @@ -114,6 +120,8 @@ func xmlDecoder(body io.Reader, v interface{}, size int64) error { lbody = body } d := xml.NewDecoder(lbody) + // Ignore any encoding set in the XML body + d.CharsetReader = nopCharsetConverter return d.Decode(v) }