Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DoS by parsing deeply nested YAML #16

Open
dtolnay opened this issue Feb 2, 2025 · 1 comment
Open

DoS by parsing deeply nested YAML #16

dtolnay opened this issue Feb 2, 2025 · 1 comment
Labels
bug Something isn't working help wanted Extra attention is needed
Milestone

Comments

@dtolnay
Copy link
Contributor

dtolnay commented Feb 2, 2025

// [dependencies]
// serde = "1"
// serde_yaml_ng = "0.10"

fn main() {
    const N: usize = 8000;
    let y = r#"{"":["#.repeat(N) + &r"]}".repeat(N);
    let begin = std::time::Instant::now();
    let serde::de::IgnoredAny = serde_yaml_ng::from_str(&y).unwrap();
    println!("{:?}", begin.elapsed());
}

At N=8k, cargo run --release takes about 1 second. At N=16k, about 4 seconds. At N=32k, 16 seconds. Each doubling of input size quadruples the runtime. This is O(n²) scaling, which is risky for many use cases because relatively small amounts of untrusted input can tie up enormous amount of CPU time.

@acatton acatton added bug Something isn't working help wanted Extra attention is needed labels Feb 2, 2025
@acatton acatton added this to the 1.0: Stable milestone Feb 2, 2025
@acatton
Copy link
Owner

acatton commented Feb 2, 2025

That's a fair point. I think this is blocking 1.0.

I would like to address that once I've fixed #5, as I think we'll have a clearer view on where is the responsibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants