Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c06b661
fix(engine): a saved step that opens a project from its text requires…
jgregoriorincon Dec 2, 2026
0671cfc
fix(engine): read a text that several steps open once, not once per s…
jgregoriorincon Dec 2, 2026
cbc1e15
fix(engine): key what a walk has read by the text, not by a digest of…
jgregoriorincon Dec 2, 2026
e0bf464
fix(engine): look a read text up without copying it, and say the cach…
jgregoriorincon Dec 2, 2026
afbc88f
fix(engine): keep a digest of what a walk has read, and require every…
jgregoriorincon Dec 2, 2026
ec71b52
fix(engine): hash the text a step opens in place, and say what the de…
jgregoriorincon Dec 2, 2026
06ac65c
fix(engine): bound the bytes a walk reads by what a project may hold …
jgregoriorincon Dec 2, 2026
0ab1fb5
fix(engine): decode nothing once a walk has spent its bytes (#3462)
jgregoriorincon Dec 2, 2026
30864f1
refactor(engine): make the walk of opened projects easier to read, an…
jgregoriorincon Dec 2, 2026
c79f1da
fix(engine): make what a walk requires the same on every computer (#3…
jgregoriorincon Dec 2, 2026
6cba044
fix(engine): decode a template within the walk's budget, not this com…
jgregoriorincon Dec 2, 2026
b216a9e
test(engine): drop a redundant import in the stack test (#3462)
jgregoriorincon Dec 2, 2026
779b473
fix(engine): bound the time a walk spends reading opened texts (#3462)
jgregoriorincon Dec 2, 2026
8742b0a
fix(engine): inflate a zipped template only within the walk's budget …
jgregoriorincon Dec 2, 2026
f355ec4
fix(engine): keep the zip limit of inline_text, and make the stack te…
jgregoriorincon Dec 2, 2026
17983bc
test(engine): the stack test compares every capability the depth limi…
jgregoriorincon Dec 2, 2026
170e565
docs(engine): say which limit each argument of inline_text_within is …
jgregoriorincon Dec 2, 2026
6c90ffa
docs(engine): say the walk of opened projects has no Cancel check (#3…
jgregoriorincon Dec 2, 2026
7b2f5ef
fix(engine): answer a text longer than the walk's budget before hashi…
jgregoriorincon Dec 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions crates/engine/src/cmd/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,13 @@ pub(crate) fn read_text(p: &Value) -> Result<String, String> {

/// The project JSON inside a package.
pub fn package_text(bytes: &[u8]) -> Result<String, String> {
let entries = rustgis_data::zip::read_matching(bytes, |n| crate::project::is_project_file(n) || n.ends_with(".rgismap"))?;
package_text_within(bytes, rustgis_data::zip::MAX_TOTAL)
}

/// [`package_text`] inflating at most `budget` bytes (and never more than [`rustgis_data::zip::MAX_TOTAL`]).
pub fn package_text_within(bytes: &[u8], budget: usize) -> Result<String, String> {
let entries =
rustgis_data::zip::read_matching_within(bytes, |n| crate::project::is_project_file(n) || n.ends_with(".rgismap"), budget)?;
let (_, data) = entries
.into_iter()
.find(|(n, _)| crate::project::is_project_file(n) || n.ends_with(".rgismap"))
Expand Down Expand Up @@ -2151,19 +2157,27 @@ pub(crate) fn durable_bytes_with<T: crate::durable::Durable>(
/// Decodes the same data-before-text choice without opening a path. `text` is lent, not copied:
/// every save asks each capability check about it.
pub(crate) fn inline_text(p: &Value) -> Result<Option<Cow<'_, str>>, String> {
inline_text_within(p, max_file(), rustgis_data::zip::MAX_TOTAL)
}

/// [`inline_text`] with the sizes given: `limit` for the text, or for the base64 of `data`, and
/// `inflated` for what a package inflates to (at most [`rustgis_data::zip::MAX_TOTAL`]).
/// [`inline_text`] passes this computer's file limit and the zip limit; the project walk passes its
/// own budget for both.
pub(crate) fn inline_text_within(p: &Value, limit: u64, inflated: usize) -> Result<Option<Cow<'_, str>>, String> {
if let Some(d) = ps(p, "data") {
use base64::Engine;
if d.len() as u64 > max_file() / 3 * 4 {
if d.len() as u64 > (limit / 3).saturating_mul(4) {
return Err(too_large());
}
let bytes = base64::engine::general_purpose::STANDARD.decode(d.trim()).map_err(|_| "data must be base64".to_string())?;
if bytes.starts_with(b"PK") {
return package_text(&bytes).map(|t| Some(t.into()));
return package_text_within(&bytes, inflated.min(rustgis_data::zip::MAX_TOTAL)).map(|t| Some(t.into()));
}
return String::from_utf8(bytes).map(|t| Some(t.into())).map_err(|_| "not a RustGIS file".to_string());
}
match ps(p, "text") {
Some(t) if t.len() as u64 <= max_file() => Ok(Some(t.into())),
Some(t) if t.len() as u64 <= limit => Ok(Some(t.into())),
Some(_) => Err(too_large()),
None => Ok(None),
}
Expand Down
Loading
Loading