fix(anatomy): V1-2.2 frame slack on the span only, non-finite bounds refused

Security review: the edge slack grew with the frame's offset (a frame at
1e15 accepted a circle 4000 units past its edge) and f64 min/max drop a
NaN bound. The slack now follows the span only; a non-finite bound is
unreadable, never in frame.
This commit is contained in:
bchanot committed 2026-10-31 23:36:18 +01:00
1 parent 587cbb2b5d
commit 9e49ed1b4d
2 files changed
+26 -4

No files matched your search

+11 -4
View File
@@ -24,7 +24,8 @@ pub struct Frame {
pub height: f64,
}
/// Rounding slack on the edges, relative to the frame's span: far below a device pixel.
/// Rounding slack on the edges, relative to the frame's span only (never to its offset): far
/// below a device pixel.
const EDGE_TOLERANCE: f64 = 1e-9;
impl Frame {
@@ -52,8 +53,7 @@ impl Frame {
}
fn holds(&self, bounds: &Bounds) -> bool {
let slack =
EDGE_TOLERANCE * (self.width.max(self.height) + self.min_x.abs().max(self.min_y.abs()));
let slack = EDGE_TOLERANCE * self.width.max(self.height);
bounds.min_x >= self.min_x - slack
&& bounds.min_y >= self.min_y - slack
&& bounds.max_x <= self.min_x + self.width + slack
@@ -107,8 +107,15 @@ pub fn geometry_bounds(geometry: &Geometry) -> Option<Bounds> {
}
}
/// A bound that is not a finite number (`f64::min` and `max` would drop a NaN) is unreadable,
/// never in frame.
pub fn placement(geometry: &Geometry, frame: &Frame) -> Placement {
match geometry_bounds(geometry) {
let finite = |b: &Bounds| {
[b.min_x, b.min_y, b.max_x, b.max_y]
.iter()
.all(|n| n.is_finite())
};
match geometry_bounds(geometry).filter(finite) {
None => Placement::Unreadable,
Some(bounds) if frame.holds(&bounds) => Placement::InFrame,
Some(_) => Placement::OutOfFrame,
+15
View File
@@ -407,3 +407,18 @@ fn both_composers_frame_the_view_on_the_measured_frame() {
assert_eq!(composed.attr("preserveAspectRatio"), None);
}
}
/// The edge slack follows the frame's span, never its offset: a frame far from the origin
/// keeps the same strictness (security review of the three-MEDIUM brief).
#[test]
fn a_frame_far_from_the_origin_is_as_strict() {
let far = |cx: f64| {
with_view_box(
&with_geometry("main", circle(cx, 5.0, 1.0)),
0,
json!({ "min_x": 1e15, "min_y": 0, "width": 1000, "height": 10 }),
)
};
assert!(accepted(&far(1e15 + 500.0)));
assert!(!accepted(&far(1e15 + 5000.0)));
}