From 736bae3f78dde83f6495e7a0000d3f4a5b945338 Mon Sep 17 00:00:00 2001 From: Gianmaria Del Monte Date: Thu, 14 Oct 2021 14:50:40 +0200 Subject: [PATCH 1/2] Fix archiver max size reached error: skipped the directories to the size count --- .../services/archiver/manager/archiver.go | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/internal/http/services/archiver/manager/archiver.go b/internal/http/services/archiver/manager/archiver.go index 63f5b9b3f1..a410fe63b0 100644 --- a/internal/http/services/archiver/manager/archiver.go +++ b/internal/http/services/archiver/manager/archiver.go @@ -136,13 +136,21 @@ func (a *Archiver) CreateTar(ctx context.Context, dst io.Writer) error { return err } + isDir := info.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER + filesCount++ if filesCount > a.config.MaxNumFiles { return ErrMaxFileCount } - sizeFiles += int64(info.Size) - if sizeFiles > a.config.MaxSize { - return ErrMaxSize + + if !isDir { + // only add the size if the resource is not a directory + // as its size could be resursive-computed, and we would + // count the files not only once + sizeFiles += int64(info.Size) + if sizeFiles > a.config.MaxSize { + return ErrMaxSize + } } // TODO (gdelmont): remove duplicates if the resources requested overlaps @@ -157,8 +165,6 @@ func (a *Archiver) CreateTar(ctx context.Context, dst io.Writer) error { ModTime: time.Unix(int64(info.Mtime.Seconds), 0), } - isDir := info.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER - if isDir { // the resource is a folder header.Mode = 0755 @@ -204,13 +210,21 @@ func (a *Archiver) CreateZip(ctx context.Context, dst io.Writer) error { return err } + isDir := info.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER + filesCount++ if filesCount > a.config.MaxNumFiles { return ErrMaxFileCount } - sizeFiles += int64(info.Size) - if sizeFiles > a.config.MaxSize { - return ErrMaxSize + + if !isDir { + // only add the size if the resource is not a directory + // as its size could be resursive-computed, and we would + // count the files not only once + sizeFiles += int64(info.Size) + if sizeFiles > a.config.MaxSize { + return ErrMaxSize + } } // TODO (gdelmont): remove duplicates if the resources requested overlaps @@ -228,8 +242,6 @@ func (a *Archiver) CreateZip(ctx context.Context, dst io.Writer) error { Modified: time.Unix(int64(info.Mtime.Seconds), 0), } - isDir := info.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER - if isDir { header.Name += "/" } else { From 5bafcc65c29ff1c406abe35df78f0c11fd8a30d4 Mon Sep 17 00:00:00 2001 From: Gianmaria Del Monte Date: Thu, 14 Oct 2021 14:56:31 +0200 Subject: [PATCH 2/2] Add changelog --- changelog/unreleased/archiver-fix-max-size.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 changelog/unreleased/archiver-fix-max-size.md diff --git a/changelog/unreleased/archiver-fix-max-size.md b/changelog/unreleased/archiver-fix-max-size.md new file mode 100644 index 0000000000..911c480b44 --- /dev/null +++ b/changelog/unreleased/archiver-fix-max-size.md @@ -0,0 +1,10 @@ +Bugfix: Fix archiver max size reached error + +Previously in the total size count of the files being +archived, the folders were taken into account, and this +could cause a false max size reached error because the +size of a directory is recursive-computed, causing the +archive to be truncated. Now in the size count, the +directories are skipped. + +https://github.com/cs3org/reva/pull/2173