Skip to content

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

hayro-cmap patch: truncated metadata-only streams report failure

Charan Rathoree08950c8e673
diff --git a/vendor/hayro-cmap/src/lib.rs b/vendor/hayro-cmap/src/lib.rs
index c45cc0ae5..4eb88f505 100644
--- a/vendor/hayro-cmap/src/lib.rs
+++ b/vendor/hayro-cmap/src/lib.rs
@@ -1125,6 +1125,18 @@ endbfchar
assert!(CMap::parse(b"<00", |_| None).is_none());
}
+ #[test]
+ fn truncated_stream_with_only_metadata_reports_failure() {
+ // Character-collection metadata alone is not a usable CMap: an empty
+ // metadata-only map would block the caller's fallback paths, so a
+ // truncated stream with no mappings must report failure here too.
+ assert!(CMap::parse(
+ b"/Registry (Adobe) /Ordering (Japan1) /Supplement 0 <00",
+ |_| None
+ )
+ .is_none());
+ }
+
#[test]
fn bad_bfchar_code_keeps_later_entries_aligned() {
// The malformed 5-byte code still has a destination object; both
diff --git a/vendor/hayro-cmap/src/parse.rs b/vendor/hayro-cmap/src/parse.rs
index 9450bbbe2..2a89fdbac 100644
--- a/vendor/hayro-cmap/src/parse.rs
+++ b/vendor/hayro-cmap/src/parse.rs
@@ -154,7 +154,6 @@ pub(crate) fn parse_inner<'a>(
&& notdef_ranges.is_empty()
&& bf_entries.is_empty()
&& base.is_none()
- && metadata.character_collection.is_none()
{
return None;
}