git.delta.rocks / jrsonnet / refs/commits / 112adb2810f2

difftreelog

fix guard against deep recursion in toml

sonxoxzuYaroslav Bolyukin2026-04-25parent: #d5225b8.patch.diff
in: master

1 file changed

modifiedcrates/jrsonnet-stdlib/src/manifest/toml.rsdiffbeforeafterboth
1use std::borrow::Cow;1use std::borrow::Cow;
22
3use jrsonnet_evaluator::{3use jrsonnet_evaluator::{
4 IStr, ObjValue, Result, ResultExt, Val, bail, in_description_frame,4 Error, IStr, ObjValue, Result, ResultExt, Val, bail, ensure_sufficient_stack, in_description_frame, manifest::{ManifestFormat, escape_string_json_buf}, val::ArrValue
5 manifest::{ManifestFormat, escape_string_json_buf},
6 val::ArrValue,
7};5};
86
9pub struct TomlFormat<'s> {7pub struct TomlFormat<'s> {
104 Val::Num(n) => write!(buf, "{n}").unwrap(),102 Val::Num(n) => write!(buf, "{n}").unwrap(),
105 #[cfg(feature = "exp-bigint")]103 #[cfg(feature = "exp-bigint")]
106 Val::BigInt(n) => write!(buf, "{n}").unwrap(),104 Val::BigInt(n) => write!(buf, "{n}").unwrap(),
107 Val::Arr(a) => {105 Val::Arr(a) => ensure_sufficient_stack(|| {
108 buf.push('[');106 buf.push('[');
109107
110 let mut had_items = false;108 let mut had_items = false;
137 buf.push_str(cur_padding);135 buf.push_str(cur_padding);
138 }136 }
139 buf.push(']');137 buf.push(']');
138 Ok::<_, Error>(())
140 }139 })?,
141 Val::Obj(o) => {140 Val::Obj(o) => ensure_sufficient_stack(|| {
142 o.run_assertions()?;141 o.run_assertions()?;
143 buf.push('{');142 buf.push('{');
144143
171 }170 }
172171
173 buf.push('}');172 buf.push('}');
173 Ok::<_, Error>(())
174 }174 })?,
175 Val::Null => {175 Val::Null => {
176 bail!("tried to manifest null")176 bail!("tried to manifest null")
177 }177 }
218 }218 }
219 first = false;219 first = false;
220 path.push(k.clone());220 path.push(k.clone());
221 in_description_frame(221 ensure_sufficient_stack(|| in_description_frame(
222 || format!("section <{k}> manifestification"),222 || format!("section <{k}> manifestification"),
223 || match v {223 || match v {
224 Val::Obj(obj) => manifest_table(&obj, path, buf, cur_padding, options),224 Val::Obj(obj) => manifest_table(&obj, path, buf, cur_padding, options),
225 Val::Arr(arr) => manifest_table_array(&arr, path, buf, cur_padding, options),225 Val::Arr(arr) => manifest_table_array(&arr, path, buf, cur_padding, options),
226 _ => unreachable!("iterating over sections"),226 _ => unreachable!("iterating over sections"),
227 },227 },
228 )?;228 ))?;
229 path.pop();229 path.pop();
230 }230 }
231 Ok(())231 Ok(())