Skip to main content

DecodeContext

Struct DecodeContext 

Source
pub struct DecodeContext<'a> { /* private fields */ }
Expand description

Shared monotonic decode state.

Implementations§

Source§

impl<'a> DecodeContext<'a>

Source

pub fn read_root( reader: &mut dyn ReadSeek, arena: &'a DecodeArena, policy: &DecodePolicy, ) -> Result<(Self, View<'a>), CodecError>

Reads the root input under max_input_bytes, copies it into the arena, registers the root space, establishes input-proportional allowances, and returns the context and root view.

Source

pub fn from_root_bytes( bytes: &'a [u8], arena: &'a DecodeArena, policy: &DecodePolicy, ) -> Result<(Self, View<'a>), CodecError>

Builds a context over caller-owned root bytes, for fuzz targets and tests. The arena still backs any expansions produced during decode.

Source

pub fn policy(&self) -> &DecodePolicy

Returns the decode policy in force.

Source

pub fn container_only(&self) -> bool

Returns whether the caller requested container-only decoding.

Source

pub fn set_container_only(&mut self, value: bool)

Records the caller’s container-only request before decoding begins.

Source

pub fn space_descriptors(&self) -> Vec<SpaceDescriptor>

Returns the stable descriptors registered for this decode session.

Source

pub fn resolve_location(&self, location: SourceLocation) -> ResolvedAddress

Resolves a session-local location into an owned root-to-leaf address.

Source

pub fn reserve_scoped( &self, bytes: u64, operation: &'static str, location: Option<SourceLocation>, ) -> Result<ScopedReservation<'_>, CodecError>

Reserves bytes held by a temporary materialization.

Source

pub fn charge_retained( &self, bytes: u64, operation: &'static str, location: Option<SourceLocation>, ) -> Result<(), CodecError>

Charges bytes retained for the remainder of this session.

Source

pub fn copy_retained( &self, bytes: &[u8], operation: &'static str, location: Option<SourceLocation>, ) -> Result<Vec<u8>, CodecError>

Copies bytes into session-retained storage after charging and reserving safely.

Source

pub fn alloc_filled<T: Clone>( &self, count: usize, value: T, operation: &'static str, ) -> Result<Vec<T>, CodecError>

Allocates count copies of value after charging collection items and reserving without panicking on allocator refusal.

Prefer this over vec![value; parsed_count] for attacker-influenced sizes.

Source

pub fn charge_entities( &self, count: u64, operation: &'static str, ) -> Result<(), CodecError>

Charges admitted entities.

Source

pub fn admit_entities( &self, current: u64, admitted: &mut u64, operation: &'static str, ) -> Result<(), CodecError>

Charges entities newly present since admitted, then advances admitted.

Codecs call this at admission boundaries so max_entities refuses further work instead of only reporting after a finished IR is built.

Source

pub fn charge_collection_items( &self, count: u64, operation: &'static str, ) -> Result<(), CodecError>

Charges admitted collection items.

Source

pub fn enter_nested( &self, operation: &'static str, location: Option<SourceLocation>, ) -> Result<DepthGuard<'_>, CodecError>

Enters one recursive nesting level until the returned guard is dropped.

Source

pub fn charge_work( &self, units: u64, operation: &'static str, ) -> Result<(), CodecError>

Charges session-global algorithm work, fusing on refusal.

Source

pub fn work_budget(&self, local_limit: u64) -> WorkBudget<'_>

Creates a local work slice that also draws from the session allowance.

Source

pub fn begin_expand( &self, source: View<'_>, spec: ExpandSpec, ) -> Result<ExpandWriter<'_, 'a>, CodecError>

Begins an expansion whose output is charged incrementally and becomes available only after successful finalization.

Source

pub fn begin_expand_as( &self, source: View<'_>, spec: ExpandSpec, label: impl Into<String>, ) -> Result<ExpandWriter<'_, 'a>, CodecError>

Begins a labeled expansion so the derived space resolves to label.

Source

pub fn concat_views(&self, inputs: &[View<'_>]) -> Result<View<'a>, CodecError>

Copies several input extents into one derived view.

Source

pub fn register_slice<'v>( &self, parent: View<'v>, range: ByteRange, ) -> Result<View<'v>, CodecError>

Registers a stored (uncompressed) child range as a space that borrows the parent bytes without copying.

range is expressed in the parent view’s own space coordinates and must lie within the parent window; a range that escapes the parent is refused here, at the request site, exactly as View::child refuses. No bytes are copied. It is the archive-entry counterpart of DecodeContext::begin_expand — stored ZIP entries take this path, compressed ones take the expander. Registration still refuses on a fused context so a stored entry cannot be admitted after a refusal.

Source

pub fn register_slice_as<'v>( &self, parent: View<'v>, range: ByteRange, label: impl Into<String>, ) -> Result<View<'v>, CodecError>

Registers a labeled stored child range so the space resolves to label.

Source

pub fn finish_session(self) -> Result<(), CodecError>

Closes a decode or inspection session, returning a fused resource error even when codec code swallowed the charge that caused it.

Trait Implementations§

Source§

impl<'a> Debug for DecodeContext<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !Freeze for DecodeContext<'a>

§

impl<'a> !RefUnwindSafe for DecodeContext<'a>

§

impl<'a> !Send for DecodeContext<'a>

§

impl<'a> !Sync for DecodeContext<'a>

§

impl<'a> !UnwindSafe for DecodeContext<'a>

§

impl<'a> Unpin for DecodeContext<'a>

§

impl<'a> UnsafeUnpin for DecodeContext<'a>

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

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.