mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-20 17:16:18 +00:00
fix(geom): keep arc subdivision bounded whatever the radius
kurbo turns an arc into cubics by radius divided by tolerance, so the fixed 0.01 let an ellipse, polygon corner, rounded rectangle, per-side stroke corner or SVG arc with a radius like 1e300 ask for more cubics than memory holds before any size check saw the geometry. Arcs now use a tolerance that scales with the radius, and SVG path data from documents, commands and imports is refused before parsing when a number passes 1e9.
This commit is contained in:
1 parent
02c38a6d95
commit
411b16931b
7 files changed
+122
-13
No files matched your search
@@ -194,7 +194,7 @@ fn create_kind(s: &mut Session, p: &Value, t: &str) -> Result<Value> {
|
||||
|
||||
/// Parse SVG path data (`M L H V C S Q T A Z`, absolute and relative) into a bezier path.
|
||||
pub fn parse_path_data(d: &str) -> Option<figcraft_geom::BezPath> {
|
||||
figcraft_geom::BezPath::from_svg(d).ok()
|
||||
figcraft_geom::svg_path(d).ok()
|
||||
}
|
||||
|
||||
/// A vector's geometry made from SVG path data (see [`path_network`]).
|
||||
@@ -213,7 +213,9 @@ pub(crate) struct PathShape {
|
||||
pub(crate) fn path_network(cmd: &str, d: &str, width: Option<f64>, height: Option<f64>) -> Result<PathShape> {
|
||||
use figcraft_geom::Shape;
|
||||
let empty = || bad(cmd, "`path` draws nothing: a vector needs a visible line or area");
|
||||
let mut path = parse_path_data(d).ok_or_else(|| bad(cmd, "`path` is not valid SVG path data"))?;
|
||||
let mut path = figcraft_geom::svg_path(d).map_err(|e| {
|
||||
if e.contains("too large") { bad(cmd, "`path` has coordinates too large to draw") } else { bad(cmd, "`path` is not valid SVG path data") }
|
||||
})?;
|
||||
let bb = path.bounding_box();
|
||||
if !(bb.x0.is_finite() && bb.y0.is_finite() && bb.width().is_finite() && bb.height().is_finite()) {
|
||||
return Err(bad(cmd, "`path` has coordinates too large to draw"));
|
||||
|
||||
Reference in new issue
Block a user