Skip to main content

validate_raw_path_str

Function validate_raw_path_str 

Source
pub fn validate_raw_path_str(path: &str) -> Result<()>
Expand description

Validates a raw, caller-supplied path string before it enters the archive pipeline. Shared by exarch-python and exarch-node. Validates a raw, caller-supplied path string before it enters the archive pipeline.

This is the shared boundary check for exarch-python and exarch-node: reject overlong strings and null bytes before doing anything else with them. It intentionally does not perform traversal, symlink, or destination-boundary checks — those require a Path, a DestDir, and a SecurityConfig, and are handled later by [super::path::validate_path].

§Check order

Length is checked before scanning for a null byte: .len() is an O(1) lookup, so an oversized input is rejected without ever running the O(n) null-byte scan below it — this serves the length check’s own DoS-prevention purpose.

§Null-byte detection

Uses str::contains, which short-circuits on the first null byte. This check validates the format of caller-supplied input (is this a well-formed path string?) rather than comparing one secret against another, so there is no timing side channel to defend against and short-circuiting is safe.

§Errors

Returns ArchiveError::SecurityViolation if path contains a null byte or exceeds MAX_PATH_LENGTH bytes.

§Examples

use exarch_core::validate_raw_path_str;

assert!(validate_raw_path_str("archive.tar.gz").is_ok());
assert!(validate_raw_path_str("bad\0path").is_err());
assert!(validate_raw_path_str(&"x".repeat(5000)).is_err());