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:
1 parent
587cbb2b5d
commit
9e49ed1b4d
2 files changed
+26
-4
No files matched your search
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user