filesafety

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMaxFileSize is the default maximum file size for safety checks (100MB)
	DefaultMaxFileSize = 100 * 1024 * 1024 // 100MB

	// SampleDatabaseMaxFileSize is the maximum file size for sample database files (10MB)
	// Sample databases should be smaller since they're downloaded from remote sources
	SampleDatabaseMaxFileSize = 10 * 1024 * 1024 // 10MB
)

Variables

This section is empty.

Functions

func SafeReadFile

func SafeReadFile(path string, opts *FileSafetyOptions) ([]byte, error)

SafeReadFile reads a file after performing safety checks. For regular files the size limit is enforced up front from Stat. Non-regular inputs (only reachable with AllowNonRegular, e.g. process substitution FIFOs) report a meaningless Stat size, so the read itself is capped at the size limit and exceeding it is an error rather than a truncation.

func ValidateFileSafety

func ValidateFileSafety(fi os.FileInfo, path string, opts *FileSafetyOptions) error

ValidateFileSafety checks if a file is safe to read based on the given options

Types

type FileSafetyOptions

type FileSafetyOptions struct {
	// MaxSize is the maximum allowed file size (0 means use DefaultMaxFileSize)
	MaxSize int64
	// AllowNonRegular allows reading from non-regular files (not recommended)
	AllowNonRegular bool
}

FileSafetyOptions configures file safety checks

Jump to

Keyboard shortcuts

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