Struct image::io::Limits

source ·
pub struct Limits {
    pub max_image_width: Option<u32>,
    pub max_image_height: Option<u32>,
    pub max_alloc: Option<u64>,
    _non_exhaustive: (),
}
Expand description

Resource limits for decoding.

Limits can be either strict or non-strict. Non-strict limits are best-effort limits where the library does not guarantee that limit will not be exceeded. Do note that it is still considered a bug if a non-strict limit is exceeded, however as some of the underlying decoders do not support not support such limits one cannot rely on these limits being supported. For stric limits the library makes a stronger guarantee that the limit will not be exceeded. Exceeding a strict limit is considered a critical bug. If a decoder cannot guarantee that it will uphold a strict limit it must fail with image::error::LimitErrorKind::Unsupported.

Currently the only strict limits supported are the max_image_width and max_image_height limits, however more will be added in the future. LimitSupport will default to support being false and decoders should enable support for the limits they support in ImageDecoder::set_limits.

The limit check should only ever fail if a limit will be exceeded or an unsupported strict limit is used.

Fields§

§max_image_width: Option<u32>

The maximum allowed image width. This limit is strict. The default is no limit.

§max_image_height: Option<u32>

The maximum allowed image height. This limit is strict. The default is no limit.

§max_alloc: Option<u64>

The maximum allowed sum of allocations allocated by the decoder at any one time excluding allocator overhead. This limit is non-strict by default and some decoders may ignore it. The default is 512MiB.

§_non_exhaustive: ()

Implementations§

source§

impl Limits

source

pub fn no_limits() -> Limits

Disable all limits.

source

pub fn check_support(&self, _supported: &LimitSupport) -> ImageResult<()>

This function checks that all currently set strict limits are supported.

source

pub fn check_dimensions(&self, width: u32, height: u32) -> ImageResult<()>

This function checks the max_image_width and max_image_height limits given the image width and height.

source

pub fn reserve(&mut self, amount: u64) -> ImageResult<()>

This function checks that the current limit allows for reserving the set amount of bytes, it then reduces the limit accordingly.

source

pub fn reserve_usize(&mut self, amount: usize) -> ImageResult<()>

This function acts identically to [reserve], but takes a usize for convenience.

source

pub fn reserve_buffer( &mut self, width: u32, height: u32, color_type: ColorType, ) -> ImageResult<()>

This function acts identically to [reserve], but accepts the width, height and color type used to create an [ImageBuffer] and does all the math for you.

source

pub fn free(&mut self, amount: u64)

This function increases the max_alloc limit with amount. Should only be used together with reserve.

source

pub fn free_usize(&mut self, amount: usize)

This function acts identically to [free], but takes a usize for convenience.

Trait Implementations§

source§

impl Clone for Limits

source§

fn clone(&self) -> Limits

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
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() -> Limits

Returns the “default value” for a type. Read more
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: &Limits) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Limits

source§

impl StructuralPartialEq for Limits

Auto Trait Implementations§

§

impl Freeze for Limits

§

impl RefUnwindSafe for Limits

§

impl Send for Limits

§

impl Sync for Limits

§

impl Unpin for Limits

§

impl UnwindSafe for Limits

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> 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
source§

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

§

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>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.