#[non_exhaustive]pub struct Limits {
pub max_bytes: usize,
pub max_strings: usize,
pub max_types: usize,
pub max_consts: usize,
pub max_const_depth: u32,
pub max_functions: usize,
pub max_insts: usize,
pub max_total_insts: usize,
pub max_items: usize,
}Expand description
The budgets the decoder enforces on untrusted input.
The defaults admit any realistic module (hundreds of megabytes of code) while bounding the work and memory a hostile file can demand. Lower them for a sandbox; there is no “unlimited” mode, because the format itself caps registers, name refs, type refs, and captures at 65,536 per function. Independently of these numbers, no list is allocated before the input is known to be long enough to hold it.
§Examples
use bytecode_lang::{decode_with, encode, DecodeErrorKind, Limit, Limits, ModuleBuilder};
let mut m = ModuleBuilder::new();
m.string("a");
m.string("b");
let bytes = encode(&m.finish().unwrap());
let mut limits = Limits::default();
limits.max_strings = 1;
let err = decode_with(&bytes, &limits).unwrap_err();
assert_eq!(err.kind(), &DecodeErrorKind::LimitExceeded(Limit::Strings));Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.max_bytes: usizeMaximum input size in bytes. Default 256 MiB.
max_strings: usizeMaximum string-table entries. Default 4,194,304.
max_types: usizeMaximum type-table entries. Default 1,048,576.
max_consts: usizeMaximum constant-pool entries. Default 4,194,304.
max_const_depth: u32Maximum nesting depth of aggregate constants (a scalar is depth 1). Default 64.
max_functions: usizeMaximum functions. Default 1,048,576.
max_insts: usizeMaximum instructions in one function. Default 16,777,216.
max_total_insts: usizeMaximum instructions in the whole module. Default 33,554,432.
max_items: usizeMaximum length of every other list: imports, globals, exports, parameters, methods, constant elements, byte-string constants (in bytes), jump-table entries, handlers, line rows, locals. Default 16,777,216.