Skip to main content

StreamLengthPolicy

Enum StreamLengthPolicy 

Source
#[non_exhaustive]
pub enum StreamLengthPolicy { Strict, RecoverFromEndstream, }
Expand description

How a stream whose /Length disagrees with the file should be handled.

This is the one deliberate strictness knob on the parser, and it exists because §7.3.8.2’s own definition of /Length is phrased in terms of the endstream keyword: the value “shall be the number of bytes from the beginning of the line following the keyword stream to the last byte just before the keyword endstream”. When the stored number and the keyword disagree, the file contains two statements of the same fact and one of them is wrong. Which one a reader believes is a policy choice, not a spec choice — so pdfcer makes it an explicit parameter rather than a hidden default.

The default is and must stay StreamLengthPolicy::Strict: on a cleanly-loading file the stored /Length is authoritative, a disagreement is real damage the operator should hear about (§7.3.8.2 calls it “an error”), and silently re-deriving extents would put a guessed span into the writer’s byte-identical re-emission path and break the round-trip/minimal-diff invariant (ARCHITECTURE.md §5).

StreamLengthPolicy::RecoverFromEndstream is reachable only from the rebuild-by-scan recovery path (crate::recover and the recovered branch of crate::document::Document::from_bytes), where the file’s cross-reference machinery has already been proven unparseable, no byte-identical re-emission is on the table (a recovered document refuses incremental save and always normalizes), and refusing an object costs the operator the whole document.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Strict

Believe /Length. A disagreement with endstream is ParseErrorKind::StreamExtentMismatch; a missing/invalid /Length is ParseErrorKind::BadStreamLength. The default, and the only policy the clean load path ever uses.

§

RecoverFromEndstream

Believe endstream. When (and only when) the stored /Length cannot be used — absent, non-integer, unresolvable, past the end of the buffer, or simply not landing on endstream — re-derive the data extent by scanning forward from the start of the data for the endstream keyword, then backing off the one end-of-line marker §7.3.8.1 says “should” precede it. Every such repair is counted in Parser::stream_lengths_recovered so it can be disclosed (R20, fuzzy-never-sneaky) rather than silently absorbed.

Trait Implementations§

Source§

impl Clone for StreamLengthPolicy

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 StreamLengthPolicy

Source§

impl Debug for StreamLengthPolicy

Source§

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

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

impl Default for StreamLengthPolicy

Source§

fn default() -> Self

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

impl Eq for StreamLengthPolicy

Source§

impl PartialEq for StreamLengthPolicy

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 StreamLengthPolicy

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

Source§

type Output = T

Should always be Self
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.