Skip to main content

safe_compile

Function safe_compile 

Source
pub async fn safe_compile(
    pat: &str,
    timeout_ms: u64,
) -> Result<Regex, CompressionError>
Expand description

Compile a regex pattern with DoS protection.

Applies NFA size limit (64 KiB), DFA size limit (1 MiB), and a timeout_ms deadline enforced via spawn_blocking + tokio::time::timeout.

Returns CompressionError::CompileTimeout immediately when [MAX_COMPILE_TASKS] concurrent compilations are already in-flight.

On timeout or panic from the blocking task, returns a typed error that allows the evolver’s failure counter to distinguish DoS-risk patterns from syntax errors.

§Errors