Bounds for untrusted ASDF input.
Every field is a positive integer. A file that crosses a bound returns
{:error, %ASDF.Error{}}. The defaults are:
max_tree_bytes— 16_777_216max_block_bytes— 1_073_741_824max_depth— 64max_scalar_bytes— 1_048_576max_aliases— 1_000max_nodes— 100_000max_blocks— 100_000max_comment_lines— 128max_header_line_bytes— 256
max_comment_lines counts comment lines after the #ASDF line. The next
comment after that many is reason: :too_many_comments.
Summary
Functions
Returns the default bounds.
Builds limits from opts.
Builds limits from opts and returns the struct.
Types
@type t() :: %ASDF.Limits{ max_aliases: pos_integer(), max_block_bytes: pos_integer(), max_blocks: pos_integer(), max_comment_lines: pos_integer(), max_depth: pos_integer(), max_header_line_bytes: pos_integer(), max_nodes: pos_integer(), max_scalar_bytes: pos_integer(), max_tree_bytes: pos_integer() }
One set of bounds. Each field is a positive integer.
:max_tree_bytes— most bytes read while looking for the YAML...line:max_block_bytes— largestused_sizeordata_sizeaccepted:max_depth— deepest nested YAML collection:max_scalar_bytes— longest YAML scalar:max_aliases— most alias nodes in one tree:max_nodes— most YAML nodes in one tree:max_blocks— most binary blocks in one file:max_comment_lines— most#lines after the format header:max_header_line_bytes— longest header or comment line, including#
Functions
@spec default() :: t()
Returns the default bounds.
Examples
iex> limits = ASDF.Limits.default()
...> {limits.max_depth, limits.max_comment_lines, limits.max_header_line_bytes}
{64, 128, 256}
@spec new(keyword()) :: {:ok, t()} | {:error, ASDF.Error.t()}
Builds limits from opts.
opts is a keyword list of the struct fields. Omitted fields keep the
defaults. Returns {:ok, limits}. An unknown key is
{:error, %ASDF.Error{reason: :unknown_limit}}. A non-positive integer
is reason: :invalid_limit. Does not raise.
Examples
iex> {:ok, limits} = ASDF.Limits.new(max_depth: 4)
...> limits.max_depth
4
iex> {:error, error} = ASDF.Limits.new(max_depth: 0)
...> error.reason
:invalid_limit
iex> {:error, error} = ASDF.Limits.new(nope: 1)
...> error.reason
:unknown_limit
Builds limits from opts and returns the struct.
opts is the same keyword list as new/1. Returns the %ASDF.Limits{}.
Raises ASDF.Error for an unknown key or a non-positive integer.
Examples
iex> ASDF.Limits.new!(max_depth: 4).max_depth
4
iex> ASDF.Limits.new!(max_depth: 0)
** (ASDF.Error) limit max_depth must be a positive integer, got 0