limitio

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package limitio provides bounded reads that fail loudly when an input exceeds a byte cap. It exists because the stdlib's io.LimitReader silently returns io.EOF at its limit — indistinguishable from a genuinely short input — which is the wrong behavior when the goal is to reject oversized untrusted data (decompression bombs, attacker-supplied artifacts) rather than truncate it.

The cap is inclusive: exactly max bytes is allowed; the first byte past max surfaces ErrTooLarge.

Index

Constants

This section is empty.

Variables

View Source
var ErrTooLarge = errors.New("limitio: input exceeds maximum allowed size")

ErrTooLarge is returned when a bounded read would exceed its cap.

Functions

func ReadAll

func ReadAll(r io.Reader, max int64) ([]byte, error)

ReadAll reads all of r into memory, failing with ErrTooLarge if r yields more than max bytes. It is the bounded counterpart to io.ReadAll.

func Reader

func Reader(r io.Reader, max int64) io.Reader

Reader wraps r so that reading more than max bytes in total fails with ErrTooLarge instead of silently stopping. A source that ends at or before max passes through its normal io.EOF.

Types

This section is empty.

Jump to

Keyboard shortcuts

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