fix: continue the plane depth count through model geometry
A construction plane built from model geometry resolves each of its sides through the document again. That hop restarted the recursion depth at 0, so a plane that is its own side never exceeded depth 1 and the 32-level cap never fired: a ~600-byte design file recursed until the stack overflowed and the process aborted, which no panic guard can intercept. Carry the depth on the construction context so the geometry arms continue the caller's count instead of restarting it. Fixes #143 Co-Authored-By: Claude Opus 5 <[email protected]> (cherry picked from commit 4bca1d49f27dfe9ef0140132746e1c7415daba8e)
This commit is contained in:
1 parent
a094fa46b5
commit
0b5e15e2b9
5 files changed
+60
-5
No files matched your search
@@ -150,6 +150,23 @@ fn try_bytes(bytes: &[u8]) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Hostile shapes that no mutation of a saved file produces: plane references that close a
|
||||
/// cycle, which resolve through the model and back into the document.
|
||||
fn generated() -> Vec<(String, Vec<u8>)> {
|
||||
let to = |name: &str| json!({"type": "plane", "plane": {"type": "construction", "name": name}});
|
||||
let plane = |id: u64, name: &str, side: Value| {
|
||||
json!({"id": id, "name": name, "suppressed": false, "type": "construction_plane",
|
||||
"plane": {"type": "midplane", "a": side, "b": {"type": "plane", "plane": {"type": "origin", "name": "XZ"}}}})
|
||||
};
|
||||
let design = |name: &str, features: Value| {
|
||||
json!({"format": "solvecraft/11", "name": name, "units": "mm", "params": [], "next_id": 9, "features": features}).to_string().into_bytes()
|
||||
};
|
||||
vec![
|
||||
("construction plane is its own side".into(), design("selfplane", json!([plane(1, "P1", to("P1"))]))),
|
||||
("two construction planes refer to each other".into(), design("twoplanes", json!([plane(1, "P1", to("P2")), plane(2, "P2", to("P1"))]))),
|
||||
]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn damaged_and_hostile_design_files_never_panic() {
|
||||
let mut rng = Rng(0x5eed_cafe_f00d_d00d);
|
||||
@@ -201,6 +218,7 @@ fn damaged_and_hostile_design_files_never_panic() {
|
||||
cases.push(("binary".into(), (0..4096u32).map(|i| (i.wrapping_mul(2_654_435_761) >> 24) as u8).collect()));
|
||||
all_cases.extend(cases.into_iter().map(|(what, b)| (name.clone(), what, b)));
|
||||
}
|
||||
all_cases.extend(generated().into_iter().map(|(what, b)| ("generated".to_string(), what, b)));
|
||||
let next = std::sync::atomic::AtomicUsize::new(0);
|
||||
let threads = std::thread::available_parallelism().map_or(4, |n| n.get());
|
||||
let failures: Vec<String> = std::thread::scope(|scope| {
|
||||
|
||||
Reference in new issue
Block a user