fileval

package
v0.18.3 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package fileval provides pre-parse file validation checks for tally.

These checks run before BuildKit parsing to fail fast on files that clearly aren't valid Dockerfiles: binary files, oversized files, and executable files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LooksUTF8

func LooksUTF8(path string, maxBytes int64) (bool, error)

LooksUTF8 checks whether the file at path appears to contain valid UTF-8 text. It opens the file and delegates to LooksUTF8FromReader.

func LooksUTF8FromReader

func LooksUTF8FromReader(r io.Reader, maxBytes int64) (bool, error)

LooksUTF8FromReader checks whether r appears to contain valid UTF-8 text. It reads in 32 KB chunks, carrying up to 3 trailing bytes between reads to handle code points split across chunk boundaries. It stops after maxBytes (a heuristic "looks like UTF-8" threshold) and fails fast on the first definitely-invalid chunk. Pass maxBytes <= 0 to read until EOF.

func ValidateFile

func ValidateFile(path string, maxSize int64) error

ValidateFile runs pre-parse validation checks on a file:

  1. Minimum size check (must be at least "FROM a")
  2. Maximum size check (when maxSize > 0)
  3. Executable-bit check (Unix only)
  4. UTF-8 smoke check

The file is opened once; all checks — including the UTF-8 read — operate on the same file handle to avoid TOCTOU races between os.Stat and a second open.

Types

type ExecutableFileError

type ExecutableFileError struct {
	Path string
}

ExecutableFileError is returned when a Dockerfile has the executable bit set.

func (*ExecutableFileError) Error

func (e *ExecutableFileError) Error() string

type FileTooLargeError

type FileTooLargeError struct {
	Path    string
	Size    int64
	MaxSize int64
}

FileTooLargeError is returned when a file exceeds the configured maximum size.

func (*FileTooLargeError) Error

func (e *FileTooLargeError) Error() string

type FileTooSmallError

type FileTooSmallError struct {
	Path string
	Size int64
}

FileTooSmallError is returned when a file is too small to be a valid Dockerfile.

func (*FileTooSmallError) Error

func (e *FileTooSmallError) Error() string

type NotUTF8Error

type NotUTF8Error struct {
	Path string
}

NotUTF8Error is returned when a file does not appear to be valid UTF-8 text.

func (*NotUTF8Error) Error

func (e *NotUTF8Error) Error() string

Jump to

Keyboard shortcuts

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