craft-docpath: prove a multi-megabyte UNC path parses iteratively

This commit is contained in:
Dylan M. Taylor committed 2026-11-14 14:53:16 -05:00
1 parent 5a457dda6a
commit fae9569718
1 file changed
+29
+29
View File
@@ -0,0 +1,29 @@
//! Paths long enough that a per-level recursive descent would exhaust the stack. Parsing is
//! iterative — `resolve` and `classify` reach `parse_share` at a fixed depth — so these come
//! back; a refusal is fine, a crash is not.
use craft_docpath::{classify, resolve};
/// Half a megabyte of components under a UNC share: one component per level for a parser that
/// recursed on each separator.
#[test]
fn a_half_megabyte_unc_path_comes_back() {
let mut path = String::from(r"\\?\UNC\host\share");
for _ in 0..(1 << 18) {
path.push_str(r"\d");
}
let _ = resolve(&path, None);
let _ = classify(&path);
}
/// Sixteen thousand nested verbatim prefixes: each level was a candidate recursive call when the
/// UNC prefixes were first reviewed.
#[test]
fn nested_verbatim_prefixes_come_back() {
let mut path = String::new();
for _ in 0..(1 << 14) {
path.push_str(r"\\?\UNC\");
}
let _ = resolve(&path, None);
let _ = classify(&path);
}