A border profile capped every length at 5000 mm (the largest sheet's side) but two: a centring mark's reach inside the drawing border and a trimming mark's length. A file could give either a huge whole number, such as 18446744073709551615. The read's number check passes whole numbers, so the profile took it as 1.8e19 mm, and saving wrote it as a decimal the next read refused: a drawing that saved but didn't open again. K2's fuzz test of drawing files (#3890) found it. Both now take the cap the margins have, `MAX_SIDE_MM`, in `validate`, so the file is refused when it's read. Layout's own checks against the sheet are unchanged, so a 5000 mm mark still validates and is refused only on a sheet too small for it. Tests: the hostile-profile test refuses 5000.000001 mm and 1.8e19 mm for each mark, and takes 5000 mm on its own; 4 planted faults (each cap removed or made one short) are all caught. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4c63a88fc3
commit
672ef13eb8
2 files changed
+17
-6
No files matched your search
@@ -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<f64>,
|
||||
/// 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(())
|
||||
|
||||
@@ -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:?}");
|
||||
|
||||
Reference in new issue
Block a user