Skip to content

Commit ed66357

Browse files
committed
Merge branch 'config-fuzz'
2 parents af6446a + 0dc2a0c commit ed66357

File tree

6 files changed

+49
-18
lines changed

6 files changed

+49
-18
lines changed

Cargo.lock

+11-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gix-config/src/file/write.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,19 @@ pub(crate) fn ends_with_newline(e: &[crate::parse::Event<'_>], nl: impl AsRef<[u
8383
}
8484

8585
pub(crate) fn extract_newline<'a>(e: &'a Event<'_>) -> Option<&'a BStr> {
86-
match e {
87-
Event::Newline(b) => b.as_ref().into(),
88-
_ => None,
89-
}
86+
Some(match e {
87+
Event::Newline(b) => {
88+
let nl = b.as_ref();
89+
90+
// Newlines are parsed consecutively, be sure we only take the smallest possible variant
91+
if nl.contains(&b'\r') {
92+
"\r\n".into()
93+
} else {
94+
"\n".into()
95+
}
96+
}
97+
_ => return None,
98+
})
9099
}
91100

92101
pub(crate) fn platform_newline() -> &'static BStr {

gix-config/src/parse/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub enum Event<'a> {
5959
Value(Cow<'a, BStr>),
6060
/// Represents any token used to signify a newline character. On Unix
6161
/// platforms, this is typically just `\n`, but can be any valid newline
62-
/// sequence. Multiple newlines (such as `\n\n`) will be merged as a single
62+
/// *sequence*. Multiple newlines (such as `\n\n`) will be merged as a single
6363
/// newline event containing a string of multiple newline characters.
6464
Newline(Cow<'a, BStr>),
6565
/// Any value that isn't completed. This occurs when the value is continued

gix-config/tests/file/mod.rs

+23-1
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!(file.to_bstring().len() < 1200000);
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!(serialized.len() < 2400000);
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.

gix-config/tests/mem.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn usage() {
2727
peak = ByteSize(ALLOCATOR.max_allocated() as u64),
2828
);
2929
assert!(
30-
used < 60 * 1024 * 1024,
30+
used < 80 * 1024 * 1024,
3131
"we should now start using more memory than anticipated, to keep mem-amplification low"
3232
);
3333
}

0 commit comments

Comments
 (0)