archive

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package archive extracts hostile input under size and count limits. Lexical checks reject obvious escapes, while os.Root enforces the boundary. os.Root.Symlink does not validate the target, so a final pass resolves links after every archive entry exists. Extraction is not transactional: a caller receiving an error must discard destDir because it may be partial.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPathTraversal        = errors.New("archive: entry escapes the extraction root")
	ErrAbsolutePath         = errors.New("archive: entry has an absolute path")
	ErrSymlinkEscape        = errors.New("archive: symlink target escapes the extraction root")
	ErrHardlinkEscape       = errors.New("archive: hardlink target escapes the extraction root")
	ErrDeviceNode           = errors.New("archive: entry is a device, fifo or socket node")
	ErrUnsupportedType      = errors.New("archive: entry has an unsupported type")
	ErrTooManyFiles         = errors.New("archive: entry count exceeds the configured limit")
	ErrFileTooLarge         = errors.New("archive: a single entry exceeds the configured size limit")
	ErrUncompressedTooLarge = errors.New("archive: total uncompressed size exceeds the configured limit")
	ErrCompressedTooLarge   = errors.New("archive: compressed input exceeds the configured limit")
	ErrNestingTooDeep       = errors.New("archive: entry path nesting exceeds the configured limit")
	ErrUnknownFormat        = errors.New("archive: unrecognized archive format")
)

Functions

This section is empty.

Types

type Format

type Format string

Format identifies the archive container

const (
	FormatTar   Format = "tar"
	FormatTarGz Format = "tar.gz"
	FormatZip   Format = "zip"
)

func DetectFormat

func DetectFormat(name string) (Format, error)

DetectFormat guesses the format from a file name

type Limits

type Limits struct {
	MaxCompressedBytes   int64
	MaxUncompressedBytes int64
	MaxFiles             int
	MaxFileBytes         int64
	MaxDepth             int
}

Limits bounds what Extract will do. Zero disables a given limit, which Extract treats as "unbounded" - callers scanning hostile input should always set every field.

func DefaultLimits

func DefaultLimits() Limits

DefaultLimits is a conservative ceiling for scanning a single published package or MCP-declared archive, not for general-purpose archive tools

type Result

type Result struct {
	Files             int
	Dirs              int
	UncompressedBytes int64
}

Result summarizes what Extract wrote

func Extract

func Extract(src io.Reader, format Format, destDir string, limits Limits) (Result, error)

Extract reads src and writes its regular files, directories and safe symlinks/hardlinks under destDir, which must already exist. Every write goes through an *os.Root opened on destDir, so the kernel - not a string comparison - refuses anything that would land outside it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL