-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port Decompression bomb security changes from v1 (#414)
* Add zstd support Port changes from v1 #292 * Port decompression bomb changes from v1 #412 --------- Co-authored-by: Yan Su <tsu@yaroot.net> Co-authored-by: Kent 'picat' Gruber <kent@hashicorp.com>
- Loading branch information
1 parent
492324c
commit 017a2ee
Showing
32 changed files
with
495 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package getter | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/klauspost/compress/zstd" | ||
) | ||
|
||
// TarZstdDecompressor is an implementation of Decompressor that can | ||
// decompress tar.zstd files. | ||
type TarZstdDecompressor struct { | ||
// FileSizeLimit limits the total size of all | ||
// decompressed files. | ||
// | ||
// The zero value means no limit. | ||
FileSizeLimit int64 | ||
|
||
// FilesLimit limits the number of files that are | ||
// allowed to be decompressed. | ||
// | ||
// The zero value means no limit. | ||
FilesLimit int | ||
} | ||
|
||
func (d *TarZstdDecompressor) Decompress(dst, src string, dir bool, umask os.FileMode) error { | ||
// If we're going into a directory we should make that first | ||
mkdir := dst | ||
if !dir { | ||
mkdir = filepath.Dir(dst) | ||
} | ||
if err := os.MkdirAll(mkdir, mode(0755, umask)); err != nil { | ||
return err | ||
} | ||
|
||
// File first | ||
f, err := os.Open(src) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
|
||
// Zstd compression is second | ||
zstdR, err := zstd.NewReader(f) | ||
if err != nil { | ||
return fmt.Errorf("Error opening a zstd reader for %s: %s", src, err) | ||
} | ||
defer zstdR.Close() | ||
|
||
return untar(zstdR, dst, src, dir, umask, d.FileSizeLimit, d.FilesLimit) | ||
} |
Oops, something went wrong.