fix(security): bound decoration steps, text-on-path elements, and rename expansions (#1257)

This commit is contained in:
Dylan M. Taylor
2026-10-24 04:39:12 -04:00
committed by GitHub
parent 25d48530a9
commit 0cca56984f
3 changed files with 15 additions and 2 deletions
+6
View File
@@ -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;
+1 -1
View File
@@ -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.
+8 -1
View File
@@ -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 })