Skip to content

Commit 6c0364a

Browse files
committed
reproduce a fuzz issue causing the config parsing to take too long
1 parent af6446a commit 6c0364a

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

Cargo.lock

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gix-config/tests/file/mod.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::borrow::Cow;
22

33
use bstr::{BStr, ByteSlice};
44
use gix_config::File;
5+
use gix_testtools::fixture_path_standalone;
56

67
pub fn cow_str(s: &str) -> Cow<'_, BStr> {
78
Cow::Borrowed(s.as_bytes().as_bstr())
@@ -27,7 +28,7 @@ mod open {
2728
}
2829

2930
#[test]
30-
fn fuzzed() {
31+
fn fuzzed_stackoverflow() {
3132
let file = File::from_bytes_no_includes(
3233
include_bytes!("../fixtures/fuzzed/stackoverflow-01.config"),
3334
gix_config::file::Metadata::default(),
@@ -43,6 +44,27 @@ fn fuzzed() {
4344
}
4445
}
4546

47+
#[test]
48+
fn fuzzed_long_runtime() -> crate::Result {
49+
let config = std::fs::read(fixture_path_standalone("fuzzed/long-parsetime.config"))?;
50+
let file = File::from_bytes_no_includes(&config, gix_config::file::Metadata::default(), Default::default())?;
51+
assert_eq!(file.sections().count(), 52);
52+
assert_eq!(file.to_bstring().len(), 180351853);
53+
File::from_bytes_no_includes(
54+
&file.to_bstring(),
55+
gix_config::file::Metadata::default(),
56+
Default::default(),
57+
)?;
58+
59+
let mut mutated_file = file.clone();
60+
mutated_file.append(file);
61+
assert_eq!(mutated_file.sections().count(), 52 * 2);
62+
let serialized = mutated_file.to_bstring();
63+
assert_eq!(serialized.len(), 360703706);
64+
File::from_bytes_no_includes(&serialized, gix_config::file::Metadata::default(), Default::default())?;
65+
Ok(())
66+
}
67+
4668
mod access;
4769
mod impls;
4870
mod init;
Binary file not shown.

0 commit comments

Comments
 (0)