diff --git a/crates/psd/src/smart.rs b/crates/psd/src/smart.rs
index 32cec043c..8cc140490 100644
--- a/crates/psd/src/smart.rs
+++ b/crates/psd/src/smart.rs
@@ -71,6 +71,20 @@ fn finite(value: f64) -> f64 {
fn valid_bounds([l, t, r, b]: [f64; 4]) -> bool {
[l, t, r, b].iter().all(|v| v.is_finite()) && (r - l).is_finite() && r > l && (b - t).is_finite() && b > t
}
+/// Explicit quilt rectangles must be complete even without subdivision keys.
+fn validate_quilt_bounds(d: &Descriptor) -> Result<()> {
+ if d.get("bounds").is_none() {
+ return Ok(());
+ }
+ let bounds = d
+ .get_object("bounds")
+ .and_then(|b| Some([b.get_number("Left")?, b.get_number("Top ")?, b.get_number("Rght")?, b.get_number("Btom")?]))
+ .ok_or_else(|| PsdError::Unsupported("incomplete explicit quilt bounds".into()))?;
+ if !valid_bounds(bounds.map(finite)) {
+ return Err(PsdError::Unsupported("invalid explicit quilt bounds".into()));
+ }
+ Ok(())
+}
/// The corner quad (top-left, top-right, bottom-right, bottom-left) from x0 y0 … x3 y3.
fn quad_from(t: [f64; 8]) -> [[f64; 2]; 4] {
[[t[0], t[1]], [t[2], t[3]], [t[4], t[5]], [t[6], t[7]]]
@@ -133,6 +147,14 @@ impl Warp {
/// uniform-model contract, not a guarantee of other readers' handling of coincident slices.
/// Nonfinite geometry becomes zero.
pub fn try_from_descriptor(d: &Descriptor) -> Result