From 76e24cf85afb9dc2213701d28968a6a07548fb1d Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Tue, 3 Nov 2026 14:51:51 +0000 Subject: [PATCH] address review: gather charges each call; check an array entry's length before copying it --- crates/js/src/formcalc/access.rs | 5 +++-- crates/js/src/host.rs | 12 +++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/js/src/formcalc/access.rs b/crates/js/src/formcalc/access.rs index 28392b6068..3528391bd4 100644 --- a/crates/js/src/formcalc/access.rs +++ b/crates/js/src/formcalc/access.rs @@ -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, seen: &mut HashSet, more: impl IntoIterator) -> R<()> { for i in more { self.step()?; @@ -44,7 +45,7 @@ impl Interp<'_> { } } } - Ok(()) + self.step() } /// The nodes of `v`, each once. diff --git a/crates/js/src/host.rs b/crates/js/src/host.rs index 274688d8b1..4c0211499f 100644 --- a/crates/js/src/host.rs +++ b/crates/js/src/host.rs @@ -141,7 +141,17 @@ pub(crate) fn strings(v: &JsValue, ctx: &mut Context) -> JsResult> { 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());