Files
pdfcraft/crates/prc/src/error.rs
T
KenM76andClaude Opus 5.5 b4ba4edc7f M12: PRC reader: charge copied blocks, refuse overflowing schema expressions
Review fixes from #6087:

- Picture and uncompressed blocks are charged to the parse ceiling before
  they are copied. File-structure headers may overlap, so each structure's
  copy counts. The ceiling test now includes the 3-byte picture.
- Schema expressions use checked multiply, add and subtract; an overflow is
  Malformed rather than a wrapped loop count.
- Each face's triangles are counted from its entity sizes and charged before
  it is triangulated.
- Matrix::mirrors divides each row by its largest entry before taking the
  determinants, so a mirror whose determinant underflows still reverses the
  winding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SqmHYx8FiWM5PcsoiErgp9
2026-11-03 23:58:08 -05:00

47 lines
1.8 KiB
Rust

//! The crate's error type.
/// Why a PRC stream could not be read.
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[non_exhaustive]
pub enum PrcError {
/// The data does not start with the `PRC` magic [WD 6.1.1].
#[error("not a PRC stream: missing the \"PRC\" magic")]
NotPrc,
/// A value ran past the end of its byte or bit stream.
#[error("PRC data truncated while reading {0}")]
Truncated(&'static str),
/// A structural field holds a value the format forbids.
#[error("malformed PRC: {0}")]
Malformed(String),
/// No `Double` code of up to 22 bits matched [WD 11.17].
#[error("PRC Double: no code matches the next 22 bits")]
UnknownDoubleCode,
/// A section is not a valid zlib stream.
#[error("PRC {section} section does not inflate: {reason}")]
Inflate {
/// The section's name.
section: &'static str,
/// The decoder's message.
reason: String,
},
/// The inflated sections and copied blocks together exceed the ceiling
/// ([`crate::MAX_INFLATED_BYTES`] or the caller's limit).
#[error("PRC sections inflate past the {limit}-byte ceiling")]
TooLarge {
/// The ceiling that was hit.
limit: usize,
},
/// The arrays read from one stream hold more elements than [`crate::MAX_DECODED_ELEMENTS`].
/// One bit can decode to a 4- or 8-byte element, so the inflation ceiling alone does not
/// bound the memory the arrays take.
#[error("PRC arrays decode past the {limit}-element ceiling")]
TooManyElements {
/// The ceiling that was hit.
limit: usize,
},
/// A construct this reader does not decode; the part of the file holding it cannot be
/// read past.
#[error("PRC {0} is not supported")]
Unsupported(&'static str),
}