diff --git a/crates/geom/src/drawing_sheet.rs b/crates/geom/src/drawing_sheet.rs index d2fab4604..ca5579dca 100644 --- a/crates/geom/src/drawing_sheet.rs +++ b/crates/geom/src/drawing_sheet.rs @@ -229,15 +229,15 @@ pub struct DrawingBorderProfile { /// the two. pub grid_border_mm: f64, /// How far each centring mark reaches inside the drawing border, 0 to stop it on the drawing - /// border (`None`: no centring marks). + /// border, at most [`MAX_SIDE_MM`] (`None`: no centring marks). pub centring_mark_mm: Option, /// Where each centring mark starts outside the drawing border. The trimmed sheet's edge when not /// given. #[serde(default)] pub centring_mark_start: CentringMarkStart, - /// The trimming mark's rectangles: their length along the sheet border and their width into - /// the sheet, which must leave them outside the grid reference border (`None`: no trimming - /// marks). + /// The trimming mark's rectangles: their length along the sheet border, at most + /// [`MAX_SIDE_MM`], and their width into the sheet, which must leave them outside the grid + /// reference border (`None`: no trimming marks). pub trimming_mark_mm: Option<[f64; 2]>, } @@ -363,7 +363,8 @@ impl DrawingBorderProfile { let g = self.grid_border_mm; require(g.is_finite() && g >= 0.0 && g <= narrowest, "the grid reference border lies between the sheet border and the drawing border")?; if let Some(reach) = self.centring_mark_mm { - require(reach.is_finite() && reach >= 0.0, "a centring mark ends on the drawing border or inside it")?; + let fits = reach.is_finite() && (0.0..=MAX_SIDE_MM).contains(&reach); + require(fits, "a centring mark ends on the drawing border or at most 5000 mm inside it")?; // Else it would start and end on the drawing border. let outside = match self.centring_mark_start { CentringMarkStart::SheetEdge => narrowest, @@ -372,7 +373,8 @@ impl DrawingBorderProfile { require(outside > 0.0 || reach > 0.0, "a centring mark needs room outside the drawing border to start from, or a reach inside it")?; } if let Some([length, width]) = self.trimming_mark_mm { - require(length.is_finite() && width > 0.0 && width <= length, "a trimming mark is finite, above 0 and no wider than it is long")?; + let fits = length.is_finite() && length <= MAX_SIDE_MM && width > 0.0 && width <= length; + require(fits, "a trimming mark is above 0, at most 5000 mm long and no wider than it is long")?; require(width <= narrowest - g, "a trimming mark lies between the sheet border and the grid reference border")?; } Ok(()) diff --git a/crates/geom/src/drawing_sheet_tests.rs b/crates/geom/src/drawing_sheet_tests.rs index 7a49acca9..6b6ee2612 100644 --- a/crates/geom/src/drawing_sheet_tests.rs +++ b/crates/geom/src/drawing_sheet_tests.rs @@ -362,6 +362,10 @@ fn hostile_sizes_and_profiles_are_refused() { DrawingBorderProfile { centring_mark_mm: Some(-10.0), ..iso }, DrawingBorderProfile { centring_mark_mm: Some(f64::NAN), ..iso }, DrawingBorderProfile { centring_mark_mm: Some(f64::INFINITY), ..iso }, + // No mark is longer than the largest sheet's side, so a file's huge number is refused when + // read rather than saved as one the next read refuses. + DrawingBorderProfile { centring_mark_mm: Some(5_000.000_001), ..iso }, + DrawingBorderProfile { centring_mark_mm: Some(u64::MAX as f64), ..iso }, // ...and is longer than 0: one that stops on the drawing border needs room outside it on // the side it starts from, a grid reference border or every margin. DrawingBorderProfile { grid_border_mm: 0.0, centring_mark_start: CentringMarkStart::GridBorder, ..iso }, @@ -372,6 +376,8 @@ fn hostile_sizes_and_profiles_are_refused() { DrawingBorderProfile { trimming_mark_mm: Some([f64::NAN, 5.0]), ..iso }, DrawingBorderProfile { trimming_mark_mm: Some([10.0, f64::NAN]), ..iso }, DrawingBorderProfile { trimming_mark_mm: Some([f64::INFINITY, 5.0]), ..iso }, + DrawingBorderProfile { trimming_mark_mm: Some([5_000.000_001, 5.0]), ..iso }, + DrawingBorderProfile { trimming_mark_mm: Some([u64::MAX as f64, 5.0]), ..iso }, // ...and fits between the sheet border and the grid reference border: ISO 5457's 5 mm fill // the 10 - 5 mm left exactly. DrawingBorderProfile { grid_border_mm: 5.000_001, ..full_iso_5457() }, @@ -398,6 +404,9 @@ fn hostile_sizes_and_profiles_are_refused() { }, // A trimming mark longer than half the 297 mm side. DrawingBorderProfile { trimming_mark_mm: Some([148.500_001, 5.0]), ..iso }, + // The longest marks a profile may have, on the largest sheet only. + DrawingBorderProfile { centring_mark_mm: Some(5000.0), ..iso }, + DrawingBorderProfile { trimming_mark_mm: Some([5000.0, 5.0]), ..iso }, ] { assert_eq!(profile.validate(), Ok(()), "{profile:?}"); assert!(profile.layout(&a3).is_err(), "laid out {profile:?}");