diff --git a/internal/objectstorage/posix/posix.go b/internal/objectstorage/posix/posix.go index a5f3333..21b4ea0 100644 --- a/internal/objectstorage/posix/posix.go +++ b/internal/objectstorage/posix/posix.go @@ -23,6 +23,7 @@ import ( "github.com/sorintlab/agola/internal/objectstorage/common" "github.com/sorintlab/agola/internal/objectstorage/types" + errors "golang.org/x/xerrors" ) @@ -97,8 +98,9 @@ func (s *PosixStorage) WriteObject(p string, data io.Reader, size int64, persist if err := os.MkdirAll(path.Dir(fspath), 0770); err != nil { return err } + lr := io.LimitReader(data, size) return common.WriteFileAtomicFunc(fspath, s.dataDir, s.tmpDir, 0660, persist, func(f io.Writer) error { - _, err := io.Copy(f, data) + _, err := io.Copy(f, lr) return err }) } diff --git a/internal/objectstorage/posixflat/posixflat.go b/internal/objectstorage/posixflat/posixflat.go index b59856c..cc9a659 100644 --- a/internal/objectstorage/posixflat/posixflat.go +++ b/internal/objectstorage/posixflat/posixflat.go @@ -275,8 +275,9 @@ func (s *PosixFlatStorage) WriteObject(p string, data io.Reader, size int64, per if err := os.MkdirAll(path.Dir(fspath), 0770); err != nil { return err } + lr := io.LimitReader(data, size) return common.WriteFileAtomicFunc(fspath, s.dataDir, s.tmpDir, 0660, persist, func(f io.Writer) error { - _, err := io.Copy(f, data) + _, err := io.Copy(f, lr) return err }) }