Skip to content

Commit

Permalink
Fix truncated archives (#2173)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgigi96 authored Oct 18, 2021
1 parent 00d0755 commit a241348
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
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

0 comments on commit a241348

Please sign in to comment.