Skip to main content

Limits

Struct Limits 

Source
#[non_exhaustive]
pub struct Limits { pub max_sections: u32, pub max_symbols: u32, pub max_relocations: u64, pub max_name_len: u32, pub max_name_bytes: u64, }
Expand description

Budgets for reading untrusted files.

Every reader checks its input against these before allocating for it. Section data, symbol records, and relocation records are also bounded by the input itself (a reader copies at most as many bytes of section data as the file holds, however its headers overlap), so the budgets that matter most are the ones on names: a hostile file can point many symbols at one long string, and only max_name_bytes stops that from multiplying.

The defaults sit far above what compilers produce and far below what would exhaust a machine. The struct is #[non_exhaustive]: start from Limits::default and change fields.

FieldDefaultBounds
max_sections1,048,576section headers
max_symbols16,777,216symbol table entries
max_relocations67,108,864relocation records, all sections together
max_name_len65,536 bytesone section or symbol name
max_name_bytes268,435,456 bytes (256 MiB)all names together, as copied out

§Examples

use object_lang::{Architecture, Limits, Object, ReadError, Section, SectionKind};

let mut obj = Object::relocatable(Architecture::X86_64);
obj.add_section(Section::new(".text", SectionKind::Text));
obj.add_section(Section::new(".data", SectionKind::Data));
let bytes = object_lang::elf::write(&obj)?;

let mut limits = Limits::default();
limits.max_sections = 3;
assert_eq!(
    object_lang::elf::read_with_limits(&bytes, &limits),
    Err(ReadError::LimitExceeded { limit: "max_sections" }),
);

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_sections: u32

The most section headers a file may have.

§max_symbols: u32

The most entries a symbol table may have.

§max_relocations: u64

The most relocation records, over all sections.

§max_name_len: u32

The longest a single name may be, in bytes.

§max_name_bytes: u64

The most name bytes copied out of the file, over all names.

Implementations§

Source§

impl Limits

Source

pub const DEFAULT: Limits

The default budgets, as a constant.

§Examples
use object_lang::Limits;

assert_eq!(Limits::DEFAULT, Limits::default());

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.