From fae9569718633972e168b75791a91798de850d30 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sat, 14 Nov 2026 14:53:16 -0500 Subject: [PATCH] craft-docpath: prove a multi-megabyte UNC path parses iteratively --- crates/docpath/tests/long_path.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 crates/docpath/tests/long_path.rs diff --git a/crates/docpath/tests/long_path.rs b/crates/docpath/tests/long_path.rs new file mode 100644 index 000000000..2ecf08ba1 --- /dev/null +++ b/crates/docpath/tests/long_path.rs @@ -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); +}