Skip to content

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

hayro-cmap patch: tests for the unresolved-usecmap failure guard

Charan Rathoref6521cf64eed
diff --git a/vendor/hayro-cmap/src/lib.rs b/vendor/hayro-cmap/src/lib.rs
index 4eb88f505..4786e75e5 100644
--- a/vendor/hayro-cmap/src/lib.rs
+++ b/vendor/hayro-cmap/src/lib.rs
@@ -1137,6 +1137,27 @@ endbfchar
.is_none());
}
+ #[test]
+ fn unresolved_usecmap_with_no_mappings_reports_failure() {
+ // A stream whose only content is a `usecmap` reference that cannot be
+ // resolved yields no mappings at all; returning an empty map here
+ // would block the caller's encoding fallback paths, so it must
+ // report failure exactly as a full parse failure did before.
+ assert!(CMap::parse(b"/Bogus usecmap", |_| None).is_none());
+ }
+
+ #[test]
+ fn unresolved_usecmap_keeps_local_mappings() {
+ // The same unresolved reference must not discard mappings the stream
+ // carries itself: only the missing base is dropped.
+ let cmap = CMap::parse(
+ b"/Bogus usecmap 1 beginbfchar <41> <0041> endbfchar",
+ |_| None,
+ )
+ .expect("local mappings survive an unresolved usecmap");
+ assert!(cmap.lookup_bf_string(0x41).is_some());
+ }
+
#[test]
fn bad_bfchar_code_keeps_later_entries_aligned() {
// The malformed 5-byte code still has a destination object; both