Documentation
¶
Index ¶
- Variables
- func GzipCompress(data []byte) ([]byte, error)
- func GzipCompressFile(src, dst string) error
- func GzipDecompress(data []byte) ([]byte, error)
- func GzipDecompressFile(src, dst string) error
- func GzipDecompressFileWithOptions(src, dst string, opts DecompressOptions) (err error)
- func GzipDecompressWithOptions(data []byte, opts DecompressOptions) ([]byte, error)
- func Unzip(zipPath, dstDir string) error
- func UnzipWithOptions(zipPath, dstDir string, opts DecompressOptions) error
- func Zip(zipPath string, paths []string) error
- type DecompressOptions
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrPathTraversal zip 条目名逃逸目标目录(C5a Zip-Slip)。 ErrPathTraversal = errors.New("zip entry escapes destination directory") // ErrSymlinkEntry zip 条目为符号链接,已拒绝(防经软链二次穿越)。 ErrSymlinkEntry = errors.New("zip entry is a symlink, rejected") // ErrDecompressLimit 解压大小超过上限(C5b 解压炸弹)。 ErrDecompressLimit = errors.New("decompress size limit exceeded") )
解压安全相关错误。
Functions ¶
func GzipDecompress ¶
GzipDecompress 解压缩数据。默认上限 100MB 防解压炸弹 OOM(C5b); 需解压更大文件请用 GzipDecompressWithOptions。
func GzipDecompressFile ¶
GzipDecompressFile 解压文件。默认上限 100MB 防磁盘耗尽(C5b); 需解压更大文件请用 GzipDecompressFileWithOptions。
func GzipDecompressFileWithOptions ¶ added in v1.2.0
func GzipDecompressFileWithOptions(src, dst string, opts DecompressOptions) (err error)
GzipDecompressFileWithOptions 解压文件,可配置大小上限(C5b)。
func GzipDecompressWithOptions ¶ added in v1.2.0
func GzipDecompressWithOptions(data []byte, opts DecompressOptions) ([]byte, error)
GzipDecompressWithOptions 解压缩数据,可配置大小上限(C5b)。
func Unzip ¶
Unzip 解压 zip 文件。默认启用 Zip-Slip 防护(前缀锚定 + 拒绝符号链接), 单条目上限 100MB、累计上限 1GB 防解压炸弹(C5b);需自定义上限请用 UnzipWithOptions。
func UnzipWithOptions ¶ added in v1.2.0
func UnzipWithOptions(zipPath, dstDir string, opts DecompressOptions) error
UnzipWithOptions 解压 zip 文件,可配置大小上限(C5b)。Zip-Slip 防护始终启用。
Types ¶
type DecompressOptions ¶ added in v1.2.0
type DecompressOptions struct {
// MaxBytes 单流 / 单条目解压大小上限(字节)。0 = 默认 100MB,-1 = 不限制。
MaxBytes int64
// MaxTotalBytes Unzip 累计解压大小上限(字节)。0 = 默认 1GB,-1 = 不限制。
// 仅 Unzip 生效。
MaxTotalBytes int64
}
DecompressOptions 解压安全选项。Zip-Slip 防护(前缀锚定 + 拒绝符号链接)始终启用,无需配置; 本选项仅控制解压大小上限以防解压炸弹(C5b)。
Click to show internal directories.
Click to hide internal directories.