diff --git a/pkg/storage/donut/donutdriver_test.go b/pkg/storage/donut/donutdriver_test.go index ed6e10c27..d4bd93e99 100644 --- a/pkg/storage/donut/donutdriver_test.go +++ b/pkg/storage/donut/donutdriver_test.go @@ -204,3 +204,21 @@ func (s *MySuite) TestMultipleNewObjects(c *C) { c.Assert(err, IsNil) c.Assert(listObjects, DeepEquals, []string{"obj1", "obj2"}) } + +func (s *MySuite) TestSysPrefixShouldFail(c *C) { + root, err := ioutil.TempDir(os.TempDir(), "donut-") + c.Assert(err, IsNil) + defer os.RemoveAll(root) + donut := NewDonutDriver(root) + + c.Assert(donut.CreateBucket("foo"), IsNil) + writer, err := donut.GetObjectWriter("foo", "obj1") + c.Assert(err, IsNil) + writer.Write([]byte("one")) + metadata := make(map[string]string) + metadata["foo"] = "bar" + metadata["sys.hello"] = "world" + err = writer.SetMetadata(metadata) + c.Assert(err, Not(IsNil)) + writer.Close() +} diff --git a/pkg/storage/donut/erasure.go b/pkg/storage/donut/erasure.go index 36b2eb0fa..4c85eafc5 100644 --- a/pkg/storage/donut/erasure.go +++ b/pkg/storage/donut/erasure.go @@ -11,6 +11,7 @@ import ( "errors" "github.com/minio-io/minio/pkg/encoding/erasure" "github.com/minio-io/minio/pkg/utils/split" + "strings" ) func erasureReader(readers []io.ReadCloser, donutMetadata map[string]string, writer *io.PipeWriter) { @@ -108,8 +109,8 @@ func erasureGoroutine(r *io.PipeReader, eWriter erasureWriter, isClosed chan<- b metadata["erasureK"] = "8" metadata["erasureM"] = "8" metadata["erasureTechnique"] = "Cauchy" - metadata["totalLength"] = strconv.Itoa(totalLength) metadata["md5"] = hex.EncodeToString(dataMd5sum) + metadata["totalLength"] = strconv.Itoa(totalLength) for _, nodeWriter := range eWriter.writers { if nodeWriter != nil { nodeWriter.SetMetadata(eWriter.metadata) @@ -141,6 +142,11 @@ func (d erasureWriter) CloseWithError(err error) error { } func (d erasureWriter) SetMetadata(metadata map[string]string) error { + for k, _ := range metadata { + if strings.HasPrefix(k, "sys.") { + return errors.New("Invalid key '" + k + "', cannot start with sys.'") + } + } for k := range d.metadata { delete(d.metadata, k) }