address review: gather charges each call; check an array entry's length before copying it

This commit is contained in:
Dylan M. Taylor
2026-11-03 14:51:51 +00:00
parent 29ca040548
commit 76e24cf85a
2 changed files with 14 additions and 3 deletions
+3 -2
View File
@@ -33,7 +33,8 @@ impl Interp<'_> {
}
/// `more` nodes into `out`, each once, never past [`MAX_LIST`]. Every node visited costs a
/// step, kept or not.
/// step, kept or not, and the call itself one more: a search that matches nothing still
/// costs work when it is repeated over a long list.
pub(super) fn gather(&mut self, out: &mut Vec<usize>, seen: &mut HashSet<usize>, more: impl IntoIterator<Item = usize>) -> R<()> {
for i in more {
self.step()?;
@@ -44,7 +45,7 @@ impl Interp<'_> {
}
}
}
Ok(())
self.step()
}
/// The nodes of `v`, each once.
+11 -1
View File
@@ -141,7 +141,17 @@ pub(crate) fn strings(v: &JsValue, ctx: &mut Context) -> JsResult<Vec<String>> {
let mut bytes = 0usize;
for i in 0..n {
let x = a.get(i, ctx)?;
let t = text(&x, ctx)?;
let t = if x.is_undefined() || x.is_null() {
String::new()
} else {
let js = x.to_string(ctx)?;
// Checked before the copy: UTF-16 units never outnumber the UTF-8 bytes they
// become, so this refuses nothing the byte check below would accept.
if bytes.saturating_add(js.len()) > xfa::MAX_PAYLOAD {
return Err(error(format!("the array holds more than {} bytes of text", xfa::MAX_PAYLOAD)));
}
js.to_std_string_escaped()
};
// One long string listed many times is copied once per listing: the copies
// together are held to the run's byte budget.
bytes = bytes.saturating_add(t.len());