Skip to main content

WriteError

Enum WriteError 

Source
#[non_exhaustive]
pub enum WriteError {
Show 14 variants Io(Error), Xref(XrefOutError), SpanOutOfRange { id: ObjId, span: ByteSpan, }, RedactionPending, HybridFullRewrite, ObjectNumberTooLarge { num: u32, max: u32, }, MissingObject { num: u32, }, UnknownDirtyObject { id: ObjId, }, RecoveredBaseForbidsIncremental, EncryptedSaveUnsupported, Rc4AppendRefused, EntropyUnavailable, RewriteReload(Box<DocError>), NothingToLinearize,
}
Expand description

Why a save could not be completed.

Every variant is a named, counted refusal rather than a best-effort degradation — the R27 fail-clean posture applied to the write side. A writer that guesses produces a plausible, working, wrong file, which is the worst possible failure shape for this subsystem (decision 007 W4).

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.
§

Io(Error)

File I/O failed.

§

Xref(XrefOutError)

A cross-reference section could not be emitted.

§

SpanOutOfRange

An object’s retained ByteSpan does not lie inside the document’s buffer — a provenance bug, and one that must never be papered over by emitting a truncated object.

Fields

§id: ObjId

The object whose provenance is broken.

§span: ByteSpan

The span that could not be sliced.

§

RedactionPending

A save was requested on a session that has a deferred redaction pending (pdfcer_core::edit::EditSession::apply_redactions_deferred, Pass 250.2).

A deferred redaction leaves the un-redacted content in the live session so the operator’s undo history is preserved; the removal is carried out only by pdfcer_core::edit::EditSession::save_applying_redaction, which runs the surgery over the current state and emits clean bytes. Both ordinary save modes are refused meanwhile: an incremental save would append a delta over the un-redacted base and leak the content via /Prev (ARCHITECTURE.md §5.2), and a full rewrite would emit the marks with the content still present (an unapplied redaction — a footgun, not a leak). Refusing by name, and pointing at the verb that is safe, is the honest outcome.

§

HybridFullRewrite

A full rewrite was requested for a hybrid-reference file (§7.5.8.4) whose /XRefStm pdfcer could not parse (Pass 281.0).

§NARROWED. This used to fire for EVERY hybrid file.

The original reasoning is kept verbatim, because it is instructive about how a refusal outlives its cause:

“Rebuilding that unit from a merged view requires re-deriving which objects were hidden and re-checking §7.5.8.4’s recursive visibility rule, which is Pass 3.2 work at the earliest. Normalizing the file to a single non-hybrid section instead would destroy its pre-1.5 readability, which R33 forbids outright.”

Both halves were true and the conclusion did not follow. The merged view was the obstacle, and the merge is pdfcer’s own: the loader now retains which objects the /XRefStm established (crate::document::Document::hybrid_partition), which is the single fact merge_first_wins destroyed. Nothing has to be re-derived — and re-deriving would have been wrong, because §7.5.8.4’s visibility rule says what a producer may hide while a rewrite must reproduce what this file did hide.

Nor is the file normalized: save_full emits the same three-part unit — main table with the hidden objects free at generation 65535, the stream, and an update section naming it — so the pre-1.5 view survives and R33 is honoured rather than waived.

§What it cost while it stood

R35 forces a redaction to a full rewrite — an incremental save leaves the un-redacted bytes in a prior revision — so this refusal made redaction unreachable on every hybrid file, and the remedy it named (“use incremental save”) was the one thing a redaction may not take. Reported by pdfcer-gui on the operator’s own SolidWorks drawing, which he had asked about three times.

§What still refuses

A file whose trailer names an /XRefStm that does not parse. The file says it hides objects; pdfcer cannot say which; either partition would be a guess, and a wrong guess yields a file that opens with an outline or a structure tree silently missing. A broken /XRefStm is deliberately non-fatal to loading (§7.5.8.4 guarantees the visible graph resolves without it) and is fatal to a rewrite.

§

ObjectNumberTooLarge

A full rewrite was asked to build a cross-reference table up to an object number beyond [save::MAX_REWRITE_OBJECT_NUMBER].

§7.5.4 requires a single-section full rewrite to carry one entry per object number from 0 to the highest defined in the file, so the writer’s cost is set by the largest object NUMBER rather than by how many objects the file contains. A small file naming one enormous number therefore asks for an enormous table: pdfium’s bug_455199.pdf is 1.2 KB, names 2147483648 0 obj, and would require 2,147,483,649 entries — measured at ~27 MB/s of steady allocation with the CPU pinned, i.e. about an hour of apparent progress before the allocator gives up.

Refusing by name is the honest outcome, and the alternatives are both worse: grinding is an unrecoverable freeze in the GUI, and emitting a sparse table instead would break §7.5.4’s completeness requirement — trading a hang for a malformed file.

Reading such a file is unaffected; this bounds the writer only. inspect and extract-text both succeed on the file above.

Fields

§num: u32

The highest object number the document defines.

§max: u32

The bound that was exceeded.

§

MissingObject

The document’s cross-reference table names an object the loader did not parse — the table and the object map disagree.

Fields

§num: u32

The object number with no parsed definition.

§

UnknownDirtyObject

An object named in the dirty set is not present in the document.

Fields

§id: ObjId

The object that could not be re-emitted.

§

RecoveredBaseForbidsIncremental

save_incremental was requested for a document loaded via cross-reference recovery (decision 013).

A recovered document had a broken base cross-reference table, so an incremental append is not merely undesirable but structurally impossible: the appended section’s /Prev would have to point at a cross-reference section that does not correctly exist, and the preserved base bytes are not a valid revision to build on. Its save is therefore a mandatory full rewrite (save_full, which emits a fresh valid classic cross-reference); incremental is refused by name here.

This is the recovered-base-forces-full-rewrite standing rule R67 (decision 013 §9; librarian-assigned — “R59” was proposed but R59/R60/R61 were already taken, so R67 is the assigned number). It is a sibling of R35 (redaction forces full rewrite) and R58 (removal/scrub forces full rewrite): §5.6’s “never normalize” does not bind a recovered file, because its base was already invalid.

§

EncryptedSaveUnsupported

A full rewrite was asked of a document loaded from an encrypted file (§7.6).

Load decrypts stream data in the retained buffer and strings in the parsed objects, so a full rewrite’s verbatim copies would emit a file whose /Encrypt claims encryption its content no longer has — one no reader can open. Save incrementally (which appends under the existing handler), or re-encrypt / remove encryption, which re-serialise every object.

§

Rc4AppendRefused

An incremental save of an RC4-encrypted document under the default Rc4Append::Refuse. The routes: opt in with Document::set_rc4_append (the CLI’s --allow-rc4-append), re-encrypt with AES-256, or remove the encryption. Decision 190.

§

EntropyUnavailable

The operating system’s random-number source was unreachable, so no fresh AES initialisation vector (§7.6.2) could be made. Nothing was written.

§

RewriteReload(Box<DocError>)

pdfcer could not reload a full rewrite it had just produced, so a step that needs the rewrite as a document (an optimize rebuild) stopped. A writer bug; nothing was written.

§

NothingToLinearize

Linearizing (Annex F) needs a catalog with at least one page, and the document has neither. Nothing was written.

Trait Implementations§

Source§

impl Debug for WriteError

Source§

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

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

impl Display for WriteError

Source§

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

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

impl Error for WriteError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Replaced by Error::source.
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for WriteError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<XrefOutError> for WriteError

Source§

fn from(source: XrefOutError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !RefUnwindSafe for WriteError

§

impl !UnwindSafe for WriteError

§

impl Forget for WriteError

§

impl Freeze for WriteError
where *const () is !null: Freeze, PhantomData<ErrorData<CustomOwner>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const DocError is !null: Freeze, PhantomData<DocError>: Freeze,

§

impl Move for WriteError

§

impl Send for WriteError
where Repr: Send, RawVecInner: Send, BoxRaw<DocError>: Send,

§

impl Sync for WriteError
where Repr: Sync, RawVecInner: Sync, BoxRaw<DocError>: Sync,

§

impl Unpin for WriteError
where *const () is !null: Unpin, &'static SimpleMessage: Unpin, *const Custom is !null: Unpin, *const u8 is !null: Unpin, Box<DocError>: Unpin,

§

impl UnsafeUnpin for WriteError

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

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.