Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix truncated archives #2173

Merged
merged 2 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions changelog/unreleased/archiver-fix-max-size.md
Original file line number Diff line number Diff line change
@@ -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
32 changes: 22 additions & 10 deletions internal/http/services/archiver/manager/archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down