Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

Merge upstream main ecffce69e into next

aionggeedf250b4c6c
diff --cc crates/cos/src/document.rs
index be5342c4e,a8a561e7d..639edf582
--- a/crates/cos/src/document.rs
+++ b/crates/cos/src/document.rs
@@@ -863,11 -857,14 +863,19 @@@ impl Document
&self.revisions
}
+ /// Position of the `%PDF-` header in the file: 0 unless bytes come before it.
+ pub fn header_offset(&self) -> usize {
+ self.header_offset
+ }
+
+ /// There is no cross-reference chain to append to: the index was rebuilt from object
+ /// headers because the file's own was unusable (see [`Self::repair_log`]), or the document
+ /// was built from scratch ([`Self::new_empty`]). A save writes such a document in full, even
+ /// when nothing was edited: for a repaired file that is what puts the repair on disk.
+ pub fn reconstructed(&self) -> bool {
+ self.revisions.is_empty()
+ }
+
/// Where each revision of the file ends (oldest first): the byte after the `%%EOF` (and its
/// end-of-line) that closes its cross-reference section. `data[..end]` is that revision as it
/// was saved. A linearized file's first-page section belongs to the revision it precedes, so
diff --cc parity/acrobat-features.toml
index 00a75201e,deb0d9471..a09ef8e9a
--- a/parity/acrobat-features.toml
+++ b/parity/acrobat-features.toml
@@@ -46,8 -46,8 +46,8 @@@ milestone = "M1
status = "shipped"
commands = ["file.open"]
tools = ["doc_open"]
- evidence = ["crates/cos/src/document.rs::damaged_xref_is_reconstructed", "crates/cos/src/parser.rs::indirect_stream_with_wrong_length_recovers", "crates/cos/src/document.rs::self_referential_length_does_not_overflow", "crates/cos/src/document.rs::a_table_numbered_from_1_that_begins_with_object_0_is_read_from_0"]
- notes = "A classic table numbered 1 n that begins with object 0's free entry is read from 0 (#2676) and logged."
-evidence = ["crates/cos/src/document.rs::damaged_xref_is_reconstructed", "crates/cos/src/parser.rs::indirect_stream_with_wrong_length_recovers", "crates/cos/src/document.rs::self_referential_length_does_not_overflow", "crates/engine/src/tests.rs::a_repaired_file_is_rewritten_by_save_even_without_edits", "crates/automation/tests/automation.rs::saving_a_repaired_file_puts_the_repair_on_disk", "crates/engine/src/tests.rs::a_signed_repaired_file_keeps_its_bytes_when_saved_without_edits"]
-notes = "Save and doc_save write a reconstructed file in full even when nothing was edited, so the repair reaches the disk and the saved file opens without one (#1937); a signed one keeps its bytes, so its signatures stay valid. A repair does not mark the document as having unsaved changes, so closing it does not offer to save the repaired file"
++evidence = ["crates/cos/src/document.rs::damaged_xref_is_reconstructed", "crates/cos/src/parser.rs::indirect_stream_with_wrong_length_recovers", "crates/cos/src/document.rs::self_referential_length_does_not_overflow", "crates/engine/src/tests.rs::a_repaired_file_is_rewritten_by_save_even_without_edits", "crates/automation/tests/automation.rs::saving_a_repaired_file_puts_the_repair_on_disk", "crates/engine/src/tests.rs::a_signed_repaired_file_keeps_its_bytes_when_saved_without_edits", "crates/cos/src/document.rs::a_table_numbered_from_1_that_begins_with_object_0_is_read_from_0"]
++notes = "Save and doc_save write a reconstructed file in full even when nothing was edited, so the repair reaches the disk and the saved file opens without one (#1937); a signed one keeps its bytes, so its signatures stay valid. A repair does not mark the document as having unsaved changes, so closing it does not offer to save the repaired file. A classic table numbered 1 n that begins with object 0's free entry is read from 0 (#2676) and logged."
[[feature]]
id = "core.malformed-input-safety"