mirror of
https://github.com/storytold/figcraft.git
synced 2026-10-28 20:36:55 -06:00
fix(security): bound decoration steps, text-on-path elements, and rename expansions (#1257)
This commit is contained in:
@@ -81,6 +81,9 @@ impl BatchRename {
|
||||
out.push_str(name.get(last..m.start()).unwrap_or_default());
|
||||
let (before, after) = (name.get(..m.start()).unwrap_or_default(), name.get(m.end()..).unwrap_or_default());
|
||||
expand(&self.replace, &Ctx { matched: m.as_str(), before, after, groups: Some(&caps), up, down }, &mut out);
|
||||
if out.len() >= MAX_NAME * 4 {
|
||||
break;
|
||||
}
|
||||
last = m.end();
|
||||
}
|
||||
out.push_str(name.get(last..).unwrap_or_default());
|
||||
@@ -110,6 +113,9 @@ impl BatchRename {
|
||||
fn expand(template: &str, c: &Ctx, out: &mut String) {
|
||||
let mut it = template.chars().peekable();
|
||||
while let Some(ch) = it.next() {
|
||||
if out.len() >= MAX_NAME * 4 {
|
||||
break;
|
||||
}
|
||||
if ch != '$' {
|
||||
out.push(ch);
|
||||
continue;
|
||||
|
||||
@@ -100,7 +100,7 @@ pub struct Decoration {
|
||||
}
|
||||
|
||||
/// Most dots or wave samples drawn for one decoration.
|
||||
const MAX_DECO_STEPS: usize = 20_000;
|
||||
const MAX_DECO_STEPS: usize = 2_500;
|
||||
|
||||
impl Decoration {
|
||||
/// The line's outline: a bar, a row of dots or a wave, `thickness` thick.
|
||||
|
||||
@@ -23,7 +23,14 @@ impl OnPath {
|
||||
/// Text on `tp` whose layout x = 0 sits `shift` before the start point and whose layout y
|
||||
/// `baseline` sits on the path. `None` for an empty or unmeasurable path.
|
||||
pub fn new(tp: &TextPath, shift: f64, baseline: f64) -> Option<Self> {
|
||||
let mut line = polylines(&tp.path())?.into_iter().next()?;
|
||||
let p = tp.path();
|
||||
if p.elements().len() > 20_000 {
|
||||
return None;
|
||||
}
|
||||
let mut line = polylines(&p)?.into_iter().next()?;
|
||||
if line.points.len() > 40_000 {
|
||||
return None;
|
||||
}
|
||||
// A subpath ending where it starts (an ellipse) goes round like a closed one.
|
||||
line.closed |= matches!((line.points.first(), line.points.last()), (Some(a), Some(b)) if (*a - *b).hypot() < 1e-6);
|
||||
Some(Self { origin: tp.start() * line.length() - shift, line, flip: tp.flip, baseline })
|
||||
|
||||
Reference in New Issue
Block a user