readregular

package
v1.6.29 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 3 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package readregular provides bounds-checked and type-checked file reads for regular files, rejecting non-regular files (such as FIFOs, devices, and sockets) and files that exceed an explicit size cap.

Governed by security#77 finding 3 (re-file of security#56 finding 3).

Index

Constants

View Source
const DefaultMax int64 = 16 << 20

DefaultMax is the default file size cap: 16 MiB.

Variables

This section is empty.

Functions

func Read

func Read(path string, max int64) ([]byte, error)

Read reads path if and only if it is a regular file whose size does not exceed max. It follows symlinks when stating and opening the path, verifies that the target is a regular file, checks that its stated size is within max, opens the file, confirms os.SameFile between the handle and the initial stat, and reads through io.LimitReader(file, max+1).

If the target is not regular, it returns an error naming the path and mode. If the file exceeds max (either at stat or during read), it returns an error naming the cap.

Types

This section is empty.

Jump to

Keyboard shortcuts

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