mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-25 22:39:40 +00:00
address review: gather charges each call; check an array entry's length before copying it
This commit is contained in:
@@ -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
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user