archive

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package archive handles unpacking .deb files (a Unix "ar" archive containing debian-binary, control.tar.*, and data.tar.*) and safely extracting the compressed tarballs inside, guarding against path traversal, symlink escapes, and decompression bombs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decompress

func Decompress(name string, r io.Reader) (io.Reader, error)

Decompress wraps r with the decompressor matching the data.tar.* suffix found on member.Name (.gz, .xz, .zst), or returns r unchanged for a plain .tar member.

func SafeExtractTar

func SafeExtractTar(r io.Reader, destDir string, filter FilterFunc) ([]string, error)

SafeExtractTar reads a tar stream and writes selected entries under destDir, rejecting anything that would escape destDir (path traversal, absolute paths, symlink/hardlink targets outside destDir) and enforcing a total-size cap.

Types

type ArEntry

type ArEntry struct {
	Name string
	Data []byte
}

ArEntry is one member of a Unix ar archive.

func FindMember

func FindMember(entries []ArEntry, prefixes ...string) (*ArEntry, bool)

FindMember returns the first member whose name starts with any of the given prefixes (used to locate "data.tar" regardless of its compression suffix: .gz, .xz, .zst).

func ParseAr

func ParseAr(data []byte) ([]ArEntry, error)

ParseAr splits a .deb (or any ar archive) into its named members.

type FilterFunc

type FilterFunc func(tarName string) (relDest string, ok bool)

FilterFunc decides whether a tar entry should be extracted and, if so, the destination path (relative to destDir) to write it to.

Jump to

Keyboard shortcuts

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