Documentation
¶
Overview ¶
Package archiveio detects and walks the archive containers Chainloop accepts as material values (zip, tar, tar.gz), enforcing the guards that keep a hostile archive from exhausting the host: entry-count and uncompressed-size limits, and rejection of paths that escape the extraction root.
It is a leaf package so that both the material crafters (which validate an archive from a path on disk) and the policy-input projections (which aggregate an archive already held in memory as material bytes) can share one implementation of those guards. Duplicating them would risk the two paths disagreeing about what is safe.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTooManyEntries is returned when an archive has more qualifying entries // than the configured maximum. ErrTooManyEntries = errors.New("archive exceeds the maximum number of entries") // ErrArchiveTooLarge is returned when the running uncompressed size of an // archive exceeds the configured maximum. ErrArchiveTooLarge = errors.New("archive exceeds the maximum uncompressed size") // ErrUnsafeEntry is returned when an archive entry's path is absolute or escapes the extraction root. ErrUnsafeEntry = errors.New("unsafe entry path in archive") )
Functions ¶
func WalkBytes ¶
func WalkBytes(data []byte, format Format, limits Limits, yield func(name string, r io.Reader) error) error
WalkBytes is WalkPath for an archive already held in memory. It applies the same guards, so a projection reading recorded material bytes cannot be tricked by an archive a crafter would have rejected.
Types ¶
type Format ¶
type Format int
Format identifies a supported archive container.
func DetectBytes ¶
DetectBytes reports the container format of an in-memory blob from its magic bytes alone, returning None when the bytes are not a supported archive. It is the counterpart to DetectPath for callers that already hold the content, such as a policy-input projection working from recorded material bytes.
func DetectFile ¶
DetectFile reports the container format of the file at p from its content alone, ignoring its name. A non-archive returns (None, nil).
Prefer this over DetectPath when the same content will later be detected from bytes with DetectBytes and the two decisions must agree — for example a crafter validating a value that a policy-input projection will re-read from the recorded material. DetectPath trusts the filename first, so a name can disagree with the content: a zip carrying a prepended stub still opens (its central directory is at the end) but no longer starts with the zip magic, so DetectPath calls it an archive and DetectBytes does not. Detecting from content on both sides makes such a value fail loudly at craft time instead of being accepted and then silently failing to project.
func DetectPath ¶
DetectPath reports whether path is a supported archive and, if so, its format. Detection is by extension first; for files whose extension does not match, magic bytes are used as a backstop so renamed archives are still caught. A non-archive returns (None, nil).