Documentation
¶
Overview ¶
Package archiveutil provides shared, path-traversal-safe archive extraction. It is used both by the modeld install flow (unpacking downloaded release bundles) and by node-side model receipt (unpacking a pushed OpenVINO IR bundle) — two independent callers writing untrusted archive content to disk, where a single reviewed implementation of the escape checks matters more than call-site convenience.
Index ¶
- Constants
- func ExtractTar(r io.Reader, dest string) error
- func RecoverDirectories(root string) error
- func RecoverDirectory(dst string) error
- func ReplaceDirectory(src, dst string) error
- func SafeJoin(dest, name string) (string, error)
- func SafeLinkTarget(dest, linkDir, linkname string) error
- func ValidateLinks(root *os.Root) error
- func WriteFileFromReader(root *os.Root, target string, r io.Reader, mode fs.FileMode) error
- func WriteTar(ctx context.Context, dir string, out io.Writer) error
Constants ¶
const PreviousDirectoryPrefix = ".previous-"
PreviousDirectoryPrefix reserves sibling directories for interrupted replacements.
Variables ¶
This section is empty.
Functions ¶
func ExtractTar ¶
ExtractTar unpacks a tar stream from r into dest, rejecting any entry that would escape dest (absolute paths, `..`, escaping sym/hardlinks). Regular file modes are preserved. Symlinks and hardlinks are supported but validated to stay within dest. r is a raw tar stream — callers wrap it in a gzip.Reader first for a .tar.gz archive.
func RecoverDirectories ¶
RecoverDirectories recovers interrupted replacements before a directory store opens. No reader or writer may use the store until this operation succeeds.
func RecoverDirectory ¶
RecoverDirectory restores an interrupted replacement or removes its obsolete backup. The caller must exclude other writers and readers for dst during recovery.
func ReplaceDirectory ¶
ReplaceDirectory activates src while retaining dst until activation succeeds. The caller must exclude readers and writers for dst. RecoverDirectory restores an interrupted replacement before the destination is used after a restart.
func SafeJoin ¶
SafeJoin resolves an archive entry name (forward-slash separated) against dest and guarantees the result stays within dest. It rejects empty paths, absolute paths, and `..` traversal.
func SafeLinkTarget ¶
SafeLinkTarget validates a symlink: linkDir is the directory containing the link, linkname is the (possibly relative) target as stored in the archive. The resolved target must stay within dest, and absolute targets are rejected.
func ValidateLinks ¶
ValidateLinks requires each archive symlink to resolve inside root, including forward references and chains through other symlinks.
func WriteFileFromReader ¶
WriteFileFromReader creates target (with parents) and copies r into it with the given mode. A duplicate entry cannot replace an existing file or link.
Types ¶
This section is empty.