pub struct DecodeLimits {
pub max_image_width: u32,
pub max_image_height: u32,
pub max_tile_pixels: u64,
pub max_mem_alloc: u64,
pub max_metadata_len: usize,
}Expand description
Optional resource limits for decoding untrusted input.
These guards exist only in the Rust core API (the C-ABI mirror keeps the upstream behaviour).
The limits are checked before allocations happen: codestream values that prefix a length (JP2 box lengths, marker segment lengths) are verified against the remaining stream bytes first, and the image/tile/metadata dimensions are checked against the limits before any buffer is sized from them.
max_mem_alloc == 0 means “the built-in default ceiling” (1 GiB) so a
corrupt header cannot drive a multi-gigabyte allocation out of a tiny
input; set it explicitly for larger images.
Fields§
§max_image_width: u32Maximum decoded image width in pixels (0 = unlimited).
max_image_height: u32Maximum decoded image height in pixels (0 = unlimited).
max_tile_pixels: u64Maximum tile area in pixels (tile width x tile height, 0 = unlimited).
max_mem_alloc: u64Upper bound on the memory the decode may allocate, in bytes. 0 = the built-in default ceiling (1 GiB); set explicitly for larger images. Covers the dominant buffers: the per-component image and tile data.
max_metadata_len: usizeMaximum length of a single metadata element in bytes - ICC colour profiles, JP2 header-box payloads, comments, etc. (0 = unlimited).
Implementations§
Source§impl DecodeLimits
impl DecodeLimits
Sourcepub const fn new() -> DecodeLimits
pub const fn new() -> DecodeLimits
All-zero limits (everything allowed, subject to the built-in 1 GiB decode-memory ceiling).
Sourcepub fn max_image_size(self, width: u32, height: u32) -> DecodeLimits
pub fn max_image_size(self, width: u32, height: u32) -> DecodeLimits
Cap the decoded image dimensions (either limit may be 0 = unlimited).
Sourcepub fn max_tile_pixels(self, pixels: u64) -> DecodeLimits
pub fn max_tile_pixels(self, pixels: u64) -> DecodeLimits
Cap the tile area in pixels (0 = unlimited).
Sourcepub fn max_mem_alloc(self, bytes: u64) -> DecodeLimits
pub fn max_mem_alloc(self, bytes: u64) -> DecodeLimits
Cap the decode memory budget in bytes (0 = the built-in 1 GiB default).
Sourcepub fn max_metadata_len(self, bytes: usize) -> DecodeLimits
pub fn max_metadata_len(self, bytes: usize) -> DecodeLimits
Cap the length of a single metadata element in bytes (0 = unlimited).
Trait Implementations§
Source§impl Clone for DecodeLimits
impl Clone for DecodeLimits
Source§fn clone(&self) -> DecodeLimits
fn clone(&self) -> DecodeLimits
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for DecodeLimits
Source§impl Debug for DecodeLimits
impl Debug for DecodeLimits
Source§impl Default for DecodeLimits
impl Default for DecodeLimits
Source§fn default() -> DecodeLimits
fn default() -> DecodeLimits
impl Eq for DecodeLimits
Source§impl PartialEq for DecodeLimits
impl PartialEq for DecodeLimits
impl StructuralPartialEq for DecodeLimits
Auto Trait Implementations§
impl Forget for DecodeLimits
impl Freeze for DecodeLimits
impl Move for DecodeLimits
impl RefUnwindSafe for DecodeLimits
impl Send for DecodeLimits
impl Sync for DecodeLimits
impl Unpin for DecodeLimits
impl UnsafeUnpin for DecodeLimits
impl UnwindSafe for DecodeLimits
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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