From 76ead9567c0b80b24e17b1c1f8c95546040ae785 Mon Sep 17 00:00:00 2001 From: bchanot Date: Sun, 1 Nov 2026 01:49:49 +0100 Subject: [PATCH] fix(anatomy): V1-2.2 path numbers bounded by the frame magnitude Fresh security review and verifier (MEDIUM): browsers read path data in f32 and draw nothing for an arc radius or rotation past f32::MAX (WebKit from 1e30) while the endpoints kept the verdict green. Every path and viewBox number is now read within 2^20, else the path is unreadable. Docs: section 12.12 transform table, mutation record, open zone finding. --- .../2026-11-01-v1-2-2-mutations-decisions.py | 1 + crates/core/src/anatomy/path.rs | 13 +++++++++-- crates/core/tests/sheet_marker_visibility.rs | 21 ++++++++++++++++++ docs/development/RUST.md | 22 +++++++++++++++---- 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/.claude/audits/2026-11-01-v1-2-2-mutations-decisions.py b/.claude/audits/2026-11-01-v1-2-2-mutations-decisions.py index dec072c7..593519f7 100644 --- a/.claude/audits/2026-11-01-v1-2-2-mutations-decisions.py +++ b/.claude/audits/2026-11-01-v1-2-2-mutations-decisions.py @@ -32,6 +32,7 @@ muts=[ ('N4 offset ratio unchecked',F,' && reach <= short * MAX_FRAME_OFFSET_RATIO;',' ;',VIS), ('N5 reach on the near edges only',F,' let reach = [min_x, min_y, min_x + width, min_y + height]',' let reach = [min_x, min_y]',VIS), ('N6 reach without abs',F,' .fold(0.0_f64, |m, v| m.max(v.abs()));',' .fold(0.0_f64, |m, v| m.max(*v));',VIS), + ('N8 path numbers past 2^20 read',"crates/core/src/anatomy/path.rs",' .filter(|n| n.abs() <= super::frame::MAX_FRAME_MAGNITUDE)',' .filter(|n| n.is_finite())',VIS), ('N7 non-finite accepted',F,' let usable = finite\n',' let usable = true\n','--lib'), # Equivalent: the aspect rule (long <= short * 100) refuses a zero or negative span already. ('F5 zero width accepted (moved, equivalent)',F,' && short >= MIN_FRAME_SPAN\n',' && short >= -1.0\n','sheet_frame'), diff --git a/crates/core/src/anatomy/path.rs b/crates/core/src/anatomy/path.rs index 70183438..0c8f81ca 100644 --- a/crates/core/src/anatomy/path.rs +++ b/crates/core/src/anatomy/path.rs @@ -4,6 +4,12 @@ //! number, a bad flag, an unknown command, a trailing comma, a number out of range) answers //! `None`, never a guess. Curves and arcs are measured on their shape, not on their control //! points; a moveto counts, as a subpath may start there. +//! +//! Every number is bounded by `frame::MAX_FRAME_MAGNITUDE` (owner brief 2026-11-01, security +//! review): browsers read path data in `f32` and draw nothing for a path holding a number past +//! `f32::MAX` (Chromium, WebKit; WebKit already for an arc radius of `1e30`), while a radius or a +//! rotation that big leaves the bounds unchanged. A coordinate past the bound is outside every +//! usable frame, a radius past it draws a straight segment on one. /// The smallest box holding a set of points. #[derive(Debug, Clone, Copy, PartialEq)] @@ -139,7 +145,8 @@ impl<'a> Cursor<'a> { Some(byte) } - /// `sign? (digits ('.' digits?)? | '.' digits) (('e'|'E') sign? digits)?`, finite. + /// `sign? (digits ('.' digits?)? | '.' digits) (('e'|'E') sign? digits)?`, within + /// `±MAX_FRAME_MAGNITUDE`. fn number(&mut self) -> Option { let start = self.at; if matches!(self.peek(), Some(b'+' | b'-')) { @@ -165,7 +172,9 @@ impl<'a> Cursor<'a> { } } let text = std::str::from_utf8(&self.bytes[start..self.at]).ok()?; - text.parse::().ok().filter(|n| n.is_finite()) + text.parse::() + .ok() + .filter(|n| n.abs() <= super::frame::MAX_FRAME_MAGNITUDE) } fn digits(&mut self) -> usize { diff --git a/crates/core/tests/sheet_marker_visibility.rs b/crates/core/tests/sheet_marker_visibility.rs index 78c4f3f7..a53931ca 100644 --- a/crates/core/tests/sheet_marker_visibility.rs +++ b/crates/core/tests/sheet_marker_visibility.rs @@ -360,3 +360,24 @@ fn transforms_inside_the_drawing_never_change_the_measure() { "{issues:?} {failures:?}" ); } + +/// Path numbers past `2²⁰` (security review 2026-11-01): browsers read them in `f32` and draw +/// nothing for an arc radius or a rotation past `f32::MAX` (WebKit from `1e30`), while the bounds +/// stay those of the endpoints. Refused as path data a browser would not read whole. +#[test] +fn path_numbers_past_the_frame_magnitude_are_refused() { + let main = |d: &str| codes(&on_main(path(d), "0 0 10 10")); + assert!( + main("M1 1A1048576 1048576 0 0 1 3 1L3 3L1 3Z").is_empty(), + "2^20: a straight side" + ); + for d in [ + "M1 1A1048577 1048577 0 0 1 3 1L3 3L1 3Z", + "M1 1A1e30 1e30 0 0 1 3 1L3 3L1 3Z", + "M1 1A1e39 1e39 0 0 1 3 1L3 3L1 3Z", + "M1 1A1 1 1e39 0 1 3 1L3 3L1 3Z", + "M1 1L3 1L3 3L-1e39 3Z", + ] { + assert_eq!(main(d), [OUT_OF_FRAME], "{d}"); + } +} diff --git a/docs/development/RUST.md b/docs/development/RUST.md index 1ae4abc8..97ab67da 100644 --- a/docs/development/RUST.md +++ b/docs/development/RUST.md @@ -4224,7 +4224,7 @@ sibling of the drawing, its only ancestor is the engine's root (and, in the canv application's). Consequence for drawings: a root `opacity="0"` or `display="none"` now hides the drawing alone, in every engine and both forms (before: the whole view, or nothing, depending on the engine and the form). -Proofs: `svg_marker_isolation` (5, all red on `958228a`): 22 root properties one by one and all at once never on the +Proofs: `svg_marker_isolation` (5 at lot B, all red on `958228a`; 7 since, with the census and the canvas passes): 22 root properties one by one and all at once never on the layer's ancestors, the drawing keeping them on its group, in both forms; the equine drawing; the halo outside the drawing; every interactive surface declaring its stroke and capture. Browser pixels (Chromium 156, Firefox 157, WebKit 27.2; PDF raster as `browserRasterizer`, canvas inline): the equine views identical before and after (0 px), the @@ -4252,9 +4252,9 @@ not edited; the tests apply the declared transform to their frozen side and comp | Reference | Transform | Where | |---|---|---| -| R3 highlight oracle `crates/core/tests/oracles/r3/highlight.json` (36 cases) | `with_isolated_layer`: the root keeps `xmlns`, `xmlns:xlink`, `viewBox`; its other attributes and every child before the layer go into a ``; `filter#osteo-halo` leaves the drawing for an engine `` placed before the layer; each point hitbox (circle, `pointer-events="all"`, no `stroke`) gets `stroke="none"` and `pointer-events="visibleFill"` | `tests/common/svg_tree.rs`, `anatomy_compose.rs`, `anatomy_canvas_op.rs` | +| R3 highlight oracle `crates/core/tests/oracles/r3/highlight.json` (36 cases) | `with_isolated_layer`: the root keeps `xmlns`, `xmlns:xlink`, `viewBox`; its other attributes and every child before the layer go into a ``; `filter#osteo-halo` leaves the drawing for an engine `` placed before the layer; each point hitbox (circle, `pointer-events="all"`, no `stroke`) gets `stroke="none"` and `pointer-events="visibleFill"` | `tests/common/svg_tree.rs`, `anatomy_compose.rs` (the R3 canvas goldens there and in `anatomy_canvas_op.rs` also take `with_canvas_passes`, §12.13) | | R3 canvas goldens `apps/app/tests/fixtures/goldens/r3/canvas.{main,head}.json` | `withIsolatedLayer`, the same rules on the mounted canvas tree | `tests/helpers/svgTree.ts`, `canvas.trees.test.tsx` | -| R3 layer goldens `canvas.{main,head}.layers.json` | `withDeclaredHitboxes`: the hitbox rule alone | same | +| R3 layer goldens `canvas.{main,head}.layers.json` | `withDeclaredHitboxes`, then `withCanvasPasses` (§12.13) | same | | R4.1 real-raster manifest `apps/app/tests/fixtures/pdf/r3/real/manifest.json`, call 1 `svgSha256` | edited, the one byte digest no transform can map: `a9a3155c…2c11` → `45fd4aaf…fc7f`; call 2 unchanged; `pdf-export.session.test.ts` green on all calls | the manifest (original in Git history, `87b8873`) | Unchanged and still compared as frozen: R3 `layer.json` and `sanitiser.json`, the R4 PDF digests, the step6 goldens, the @@ -4326,5 +4326,19 @@ none: Firefox counts a stroke in an element's client rect, the others do not) ag | far edge at 10⁵ and 10⁶ spans (refused, drawn raw) | `no_frame` | centre gap 0.14 px, then 11 px: the `f32` error the ratio rule keeps out | 0.44 px, 9.6 px | | span 1 unit to `2⁻²⁰`, disc a quarter of the frame, painted pixels | accepted from 1 unit (`no_frame` below) | Chromium exact to `2⁻¹⁰`, 0.46 px at `2⁻¹⁴`, nothing painted at `2⁻²⁰`; WebKit exact to `2⁻⁵`, nothing painted from `2⁻⁷` | exact at every span (its client rects drift from 286 px per unit: 3.3 % at a span of 1, rendering unaffected) | +Path numbers (fresh security review and verifier on `96b9978`, MEDIUM): every number of a path's `d` and of a `viewBox` +is read within `±2²⁰` (`path::Cursor::number`), else the path is unreadable (`out_of_frame`). Browsers read path data +in `f32` and draw nothing for an arc radius or rotation past `f32::MAX` (Chromium, WebKit; WebKit from `1e30`), while the +endpoints kept the bounds in frame and the verdict passed. `path_numbers_past_the_frame_magnitude_are_refused` (red +before the bound). Residual: a rotation below `2²⁰` degrees is reduced in `f32` by the browser (ulp 0.0625° at `10⁶`). + +Mutations on `96b9978` (`.claude/audits/2026-11-01-v1-2-2-mutations-decisions.py` and the 2026-10-30 script): 55 killed, +F5 (zero span accepted) survives as equivalent, the aspect rule refusing a zero or negative span; six 2026-10-30 anchors +moved with the code, re-anchored and killed in the new script. N8 (the path number bound) added after the review. + Declared limit: a thin shape drawn on a diagonal is measured on its bounds, so it can pass while showing a line; the -rule is a scale floor against the bypass, never a review of shapes (the zones keep their declared 2-unit stroke). +rule is a scale floor against the bypass, never a review of shapes (the zones keep their declared 2-unit stroke). The +security review measured its consequence (MEDIUM, open, owner decision): a zone path whose interior has zero winding +(an outline traced twice in opposite directions) or a near-collinear polygon passes the 4 px rule, paints no interior +and is hit only on its 2-unit stroke (0.28 CSS px on the equine phone scale), in the three engines. Closing it needs a +filled-area measure (nonzero rule) or a « zone without interior » issue.