Skip to main content

Limits

Struct Limits 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§max_bytes: usize

Maximum input size in bytes. Default 256 MiB.

§max_strings: usize

Maximum string-table entries. Default 4,194,304.

§max_types: usize

Maximum type-table entries. Default 1,048,576.

§max_consts: usize

Maximum constant-pool entries. Default 4,194,304.

§max_const_depth: u32

Maximum nesting depth of aggregate constants (a scalar is depth 1). Default 64.

§max_functions: usize

Maximum functions. Default 1,048,576.

§max_insts: usize

Maximum instructions in one function. Default 16,777,216.

§max_total_insts: usize

Maximum instructions in the whole module. Default 33,554,432.

§max_items: usize

Maximum 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.

Trait Implementations§

Source§

impl Clone for Limits

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Limits

Source§

impl Debug for Limits

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Limits

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Limits

Source§

impl Hash for Limits

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Limits

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Limits

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.