pdfrum_type1/error.rs
1//! The crate's error type.
2//!
3//! Very little here is fatal. A Type 1 program that names a subroutine it does
4//! not have, blends with a weight vector of the wrong arity, or runs off the
5//! end of a charstring yields *no outline for that glyph* — the font is still
6//! usable for every other glyph, so those cases surface as `None` from
7//! [`outline`](crate::Type1Font::outline) rather than as an `Err`.
8//!
9//! `Error` is reserved for "this blob is not a font we can use at all".
10
11/// Why a Type 1 font program could not be read.
12#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
13#[non_exhaustive]
14pub enum Error {
15 /// The blob is shorter than the smallest thing that could be a font.
16 #[error("font program is empty")]
17 Empty,
18
19 /// A PFB container's segment headers did not describe the blob: a segment
20 /// length running past the end, a tag byte other than `0x80`, or a segment
21 /// type outside 1–3.
22 ///
23 /// Carries the offset of the offending header, which is what a fuzz
24 /// reduction wants.
25 #[error("PFB segment header at {at} is not usable")]
26 PfbSegment {
27 /// Byte offset of the header that failed.
28 at: usize,
29 },
30
31 /// No `eexec` token was found, so the font has no private portion — and a
32 /// Type 1 font's charstrings live entirely inside it.
33 #[error("no eexec section")]
34 NoEexec,
35
36 /// The `eexec` section decrypted to something that is not a PostScript
37 /// private dictionary, which means the wrong bytes were fed to the cipher.
38 #[error("eexec section did not decrypt to a private dictionary")]
39 EexecGarbage,
40
41 /// The program parsed but declared no `/CharStrings`, so there is nothing
42 /// to draw.
43 #[error("font program has no CharStrings dictionary")]
44 NoCharStrings,
45}