Skip to main content

DirtySet

Struct DirtySet 

Source
pub struct DirtySet { /* private fields */ }
Expand description

The set of objects a save must write into the new revision.

§The bug this type exists to make impossible

ARCHITECTURE.md §11.1 and decision 007: the dirty set is a diff against the base revision, computed at save time — never the union of every command run during the session. The difference is not academic. An object edited and then undone is in the union but not in the diff; including it appends a revision that silently re-states the object’s original value, bloating every save after any undo and breaking the “objects pdfcer didn’t logically touch are omitted” half of the §5 invariant. §7.5.6 requirement 1 is the spec-side reason: “A cross-reference section for an incremental update shall contain entries only for objects that have been changed, replaced, or deleted.” Read the modality carefully — “only for” is a restriction, not merely permission to omit.

§Two kinds of entry, and why both live in one type

  • A re-emission (DirtySet::identity_reemission) asks the writer to write an object’s existing value into the new revision. It is a verification device, not an edit.
  • A replacement (DirtySet::replace) carries a new value. This is what an actual operator edit produces, and it is the only entry kind that counts as “changed” for DirtySet::changes_content — the /ID[1] trigger (§14.4).

Plus a trailer patch (DirtySet::patch_trailer): entries the new revision’s trailer must carry with a different value than the base trailer had. The trailer is part of a revision, not an object, so it cannot be expressed as an entry — but it is part of the same save-time diff, and threading a second parameter through every save signature would only hide that.

§Building one

Nothing here computes the diff; pdfcer_core::edit::EditSession does, and it is the only thing that should. This type is the result of that computation and the writer’s input. Constructing one by hand is legitimate for tests and for the verification modes, and is exactly how the “union of every command ever run” bug would be reintroduced if an edit path ever built one directly — so don’t.

Implementations§

Source§

impl DirtySet

Source

pub fn empty() -> Self

The empty dirty set — “this document has no unsaved changes”.

With this, save_incremental produces a file byte-identical to the input: zero edits means zero bytes, not “the input plus an empty revision”.

Source

pub fn identity_reemission(ids: impl IntoIterator<Item = ObjId>) -> Self

Build a dirty set that asks the writer to re-emit the named objects unchanged.

This is a verification constructor, not an editing API, and the distinction is worth being precise about. It changes no object’s value; it drives the §7.5.6 append machinery — object re-emission, update-section construction, /Prev chaining, trailer copying, startxref placement — over real files so that path is corpus-proven before genuine edits go through it. The resulting file is semantically identical to the input by construction, which gives the round-trip harness a strong oracle: it must reload to the same object graph and re-render to the same pixels.

Without this, Pass 3.0’s headline gate (an empty dirty set producing a byte-identical file) would exercise a memcpy and nothing else, and the append writer would have shipped untested.

Because it changes nothing, a set built this way answers false to DirtySet::changes_content and therefore does not regenerate /ID[1].

Source

pub fn replace(&mut self, id: ObjId, value: Object)

Record that id must be written with value instead of whatever it holds in the base revision.

id need not exist in the base document: an id the base does not define is a created object, which the writer appends and gives a fresh cross-reference entry. That is how a metadata edit on a file with no /Info dictionary reaches the file.

Replacing supersedes a previously recorded re-emission for the same id, and a second replacement supersedes the first — so N edits to one object produce exactly one entry in the update section, never N. That coalescing is structural (a map keyed by id), not a special case.

Source

pub fn delete(&mut self, id: ObjId)

Record that id must be deleted: no body in the new revision, and a type-0 (free) cross-reference entry that makes every reference to it resolve to null (§7.3.10, §7.5.4).

§Deleting is not redacting, and this method is not a shortcut

A deletion recorded here is a structural removal — the object leaves the document graph. Under save_incremental its previous bytes remain in the file by construction (§7.5.6 appends, it does not erase), and under save_full they are simply not re-emitted. Neither is redaction, and ARCHITECTURE.md §5.7 records why full rewrite is not sufficient there either (object-stream containers carry through verbatim in both modes). Front ends must say so — pdfce-gui’s delete tooltip does.

§Generation numbers are the writer’s business, not the caller’s

§7.5.4 makes a free entry’s generation “the generation number to be used if the object … is reused”, i.e. one more than the deleted object’s. The caller supplies only the id it wants gone; the increment (and its 65,535 saturation, which marks a number permanently unreusable) happens in [save], once, where the free-list chain is built. Letting callers pass a generation would be an invitation to get that arithmetic wrong in three places.

A delete supersedes any previously recorded change for the same id, and vice versa — the map is keyed by id, so the last word wins, which is what an editing session’s save-time diff means.

Source

pub fn is_deleted(&self, id: ObjId) -> bool

Whether id is recorded for deletion.

Source

pub fn deletions(&self) -> impl Iterator<Item = ObjId> + '_

Every id recorded for deletion, ascending.

Ascending because the free-list chain the writer builds from this runs in increasing object-number order — not a shall (§7.5.4 only requires a well-formed linked list) but the form Annex H’s examples use, and the one that keeps output deterministic and therefore byte-comparison-testable.

Source

pub fn patch_trailer(&mut self, key: Name, value: Object)

Record that the new revision’s trailer must carry key with value.

§7.5.6 requirement 3 makes an update trailer carry “all the entries except the Prev entry … from the previous trailer, whether modified or not”, so the writer starts from the base trailer and applies this patch over it. Only genuinely changed keys belong here — a patch that restates a base value is a no-op that would still flip DirtySet::changes_content, and therefore would regenerate /ID[1] on a document nothing changed in.

Source

pub fn remove_trailer_key(&mut self, key: Name)

Record that the new revision’s trailer must not carry key, which the base trailer has. Like Self::patch_trailer, only for a key the session genuinely removed; it counts as a content change.

Source

pub fn trailer_removals(&self) -> &[Name]

The trailer keys Self::remove_trailer_key recorded.

Source

pub fn is_empty(&self) -> bool

Whether the set names nothing at all — the condition under which save_incremental guarantees whole-file byte identity.

Source

pub fn len(&self) -> usize

How many object definitions the next revision will carry.

Deliberately excludes the trailer patch: the trailer is not an object and does not get a cross-reference entry.

Source

pub fn changes_content(&self) -> bool

Whether this save writes at least one changed thing — the §14.4 / R39 trigger for regenerating /ID[1].

A pure identity re-emission answers false: it writes objects, but it changes none of them, so §14.4’s “at the time it was last updated” trigger never fired. Keeping these two questions separate is what lets Pass 3.0’s append-identity corpus mode stay byte-stable while a real edit correctly refreshes /ID[1].

Source

pub fn replacement(&self, id: ObjId) -> Option<&Object>

The replacement value recorded for id, or None if this id is absent or is a bare re-emission.

Source

pub fn contains(&self, id: ObjId) -> bool

Whether id is named at all (as a replacement or a re-emission).

Source

pub const fn trailer_patch(&self) -> &Dict

The trailer entries the new revision must carry with a value different from the base trailer’s.

Source

pub fn iter(&self) -> impl Iterator<Item = ObjId> + '_

Iterate the named objects in ascending (num, generation) order.

Ascending order is not cosmetic: it is what lets the cross-reference emitters group entries into runs, which §7.5.8.2 turns into a shall for cross-reference streams (“The array shall be sorted in ascending order by object number”).

Source

pub fn set_staging(&mut self, staging: Vec<u8>)

Attach the session’s authored-stream staging buffer (R45).

Called by pdfcer_core::edit::EditSession::dirty_set when the session carries authored streams. The buffer’s bytes are the raw (still-filter-encoded, but Pass 6.1 authors raw appearances) payloads that replacement Stream values’ spans index into, in the base.len() + local combined coordinate system documented on the field.

Source

pub fn staging(&self) -> &[u8] ⓘ

The authored-stream staging buffer (empty for a pre-6.1 edit).

Source

pub fn combined_source<'a>(&'a self, base: &'a [u8]) -> Cow<'a, [u8]>

The serialization source a replacement object’s stream spans index into (R45): base alone when nothing was authored (zero-copy, the unchanged pre-6.1 path), or base ++ staging when authored streams are present.

The combined buffer is sound because a base span (< base.len()) resolves in the prefix — identical to base — while an authored span (>= base.len(), i.e. base.len() + local) resolves in the appended suffix. base must be the same buffer the session’s authored offsets were computed against, i.e. the document passed to the save function; the writer guarantees this by passing doc.bytes().

Trait Implementations§

Source§

impl Clone for DirtySet

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 Debug for DirtySet

Source§

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

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

impl Default for DirtySet

Source§

fn default() -> Self

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

impl PartialEq for DirtySet

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 DirtySet

Auto Trait Implementations§

§

impl Forget for DirtySet

§

impl Freeze for DirtySet
where *const LeafNode<ObjId, Change> is !null: Freeze, PhantomData<(Owned, LeafOrInternal)>: Freeze, PhantomData<Box<(ObjId, Change)>>: Freeze, *const u8 is !null: Freeze, PhantomData<(Name, Object)>: Freeze, PhantomData<Name>: Freeze, PhantomData<u8>: Freeze,

§

impl Move for DirtySet

§

impl RefUnwindSafe for DirtySet

§

impl Send for DirtySet
where NodeRef<Owned, ObjId, Change, LeafOrInternal>: Send, BoxRaw<(ObjId, Change)>: Send, RawVecInner: Send,

§

impl Sync for DirtySet
where NodeRef<Owned, ObjId, Change, LeafOrInternal>: Sync, BoxRaw<(ObjId, Change)>: Sync, RawVecInner: Sync,

§

impl Unpin for DirtySet
where *const LeafNode<ObjId, Change> is !null: Unpin, Box<(ObjId, Change)>: Unpin, *const u8 is !null: Unpin,

§

impl UnsafeUnpin for DirtySet
where *const LeafNode<ObjId, Change> is !null: UnsafeUnpin, PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin, PhantomData<Box<(ObjId, Change)>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<(Name, Object)>: UnsafeUnpin, PhantomData<Name>: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin,

§

impl UnwindSafe for DirtySet
where BTreeMap<ObjId, Change>: UnwindSafe, RawVecInner: UnwindSafe,

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.