Help us shape the future of Go! Take the 2026 Go Developer Survey

tomllimit

package
v0.33.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package tomllimit rejects pathologically nested TOML before it reaches a decoder. The decoder in use (BurntSushi/toml) spends memory that grows far faster than the input as nesting deepens — a 24 KB document nested a few thousand levels deep allocates over a gigabyte — and that work happens inside the decoder, below any memory accounting, so a memory limit cannot stop it. A cheap single pass over the source caps the nesting depth first.

Index

Constants

View Source
const MaxDepth = 100

MaxDepth is the deepest nesting any TOML document given to a decoder may have. Real configuration files nest a handful of levels; at this depth the decoder's memory stays at baseline, far below the catastrophic range.

Variables

This section is empty.

Functions

func Check

func Check(src string) error

Check reports an *ErrTooDeep when src nests deeper than MaxDepth, in any of the ways TOML nests: inline tables and arrays (`{` / `[` in a value), and dotted keys and table headers (`a.b.c = 1`, `[a.b.c]`). It is a single linear scan that respects strings (basic, literal and their multi-line forms) and comments, so brackets and dots inside them are not counted.

func CheckMax

func CheckMax(src string, max int) error

CheckMax is Check with an explicit cap, for testing.

Types

type ErrTooDeep

type ErrTooDeep struct{ Max int }

ErrTooDeep is returned when a document nests deeper than the cap.

func (ErrTooDeep) Error

func (e ErrTooDeep) Error() string

Jump to

Keyboard shortcuts

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