Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog.d/11560-config-path-list-linear-duplicates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- section: Fixed -->
- A `ripr.toml` listing tens of thousands of `generated_file_patterns`,
`handwritten_files` or `profiles.bun_ub.test_roots` entries no longer stalls
the run: duplicate detection is linear instead of quadratic, with the same
error wording and ordering (#11560).
11 changes: 8 additions & 3 deletions crates/ripr/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,9 @@ fn parse_languages_enabled(values: &[String]) -> Result<Vec<LanguageId>, String>

fn parse_generated_file_patterns(values: &[String]) -> Result<Vec<String>, String> {
let mut parsed = Vec::with_capacity(values.len());
// Set membership keeps duplicate detection linear: a hostile `ripr.toml`
// may list tens of thousands of entries (#11560).
let mut seen = std::collections::HashSet::with_capacity(values.len());
for value in values {
if value.chars().any(char::is_control) {
return Err(
Expand All @@ -1056,7 +1059,7 @@ fn parse_generated_file_patterns(values: &[String]) -> Result<Vec<String>, Strin
.to_string(),
);
}
if parsed.iter().any(|existing| existing == trimmed) {
if !seen.insert(trimmed) {
return Err(format!(
"languages.rust.generated_file_patterns lists `{trimmed}` more than once; remove the duplicate"
));
Expand All @@ -1073,6 +1076,7 @@ fn parse_handwritten_files(
extension_ok: impl Fn(&str) -> bool,
) -> Result<Vec<String>, String> {
let mut parsed = Vec::with_capacity(values.len());
let mut seen = std::collections::HashSet::with_capacity(values.len());
for value in values {
if value.chars().any(char::is_control) {
return Err(format!("{field} must not contain control characters"));
Expand All @@ -1091,7 +1095,7 @@ fn parse_handwritten_files(
return Err(format!("{field} must identify {extension_desc}"));
}
let normalized = path.to_string_lossy().replace('\\', "/");
if parsed.contains(&normalized) {
if !seen.insert(normalized.clone()) {
return Err(format!(
"{field} lists `{normalized}` more than once; remove the duplicate"
));
Expand All @@ -1116,10 +1120,11 @@ fn parse_bun_ub_profile(raw: RawBunUbProfileConfig) -> Result<BunUbProfileConfig
return Err("profiles.bun_ub.test_roots must list at least one test root".to_string());
}
let mut parsed_roots = Vec::with_capacity(test_roots.len());
let mut seen = std::collections::HashSet::with_capacity(test_roots.len());
for root in test_roots {
let trimmed = root.trim();
parse_relative_path("profiles.bun_ub.test_roots", trimmed)?;
if parsed_roots.iter().any(|existing| existing == trimmed) {
if !seen.insert(trimmed.to_string()) {
return Err(format!(
"profiles.bun_ub.test_roots lists `{trimmed}` more than once; remove the duplicate"
));
Expand Down
59 changes: 59 additions & 0 deletions crates/ripr/src/config/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3040,3 +3040,62 @@ fn explicit_config_wins_when_markers_and_source_both_detect() -> Result<(), Stri
let _ = fs::remove_dir_all(&root);
Ok(())
}

/// #11560: a hostile `ripr.toml` may list tens of thousands of entries. The
/// duplicate check must stay linear, and still name the first duplicate.
#[test]
fn large_path_lists_parse_in_linear_time_and_still_reject_duplicates() -> Result<(), String> {
let render = |key: &str, table: &str, entries: &[String]| {
let items = entries
.iter()
.map(|entry| format!("\"{entry}\""))
.collect::<Vec<_>>()
.join(",");
format!("[{table}]\n{key} = [{items}]\n")
};
let patterns: Vec<String> = (0..60_000).map(|i| format!("gen{i}/**/*.rs")).collect();
let files: Vec<String> = (0..60_000).map(|i| format!("src/f{i}.rs")).collect();
let roots: Vec<String> = (0..60_000).map(|i| format!("tests/t{i}")).collect();
let started = std::time::Instant::now();
let config = parse_config(&render(
"generated_file_patterns",
"languages.rust",
&patterns,
))?;
assert_eq!(
config.languages().rust.generated_file_patterns.len(),
60_000
);
let config = parse_config(&render("handwritten_files", "languages.rust", &files))?;
assert_eq!(config.languages().rust.handwritten_files.len(), 60_000);
let bun = format!(
"{}bridge_hints = \"hints.json\"\n",
render("test_roots", "profiles.bun_ub", &roots)
);
let config = parse_config(&bun)?;
assert_eq!(
config
.profiles()
.bun_ub
.as_ref()
.map(|p| p.test_roots.len()),
Some(60_000)
);
assert!(
started.elapsed() < std::time::Duration::from_secs(10),
"60k-entry path lists must parse in linear time, took {:?}",
started.elapsed()
);

let mut duplicated = patterns.clone();
duplicated.push("gen17/**/*.rs".to_string());
let error = parse_config(&render(
"generated_file_patterns",
"languages.rust",
&duplicated,
))
.err()
.ok_or("duplicate pattern must be rejected")?;
assert!(error.contains("`gen17/**/*.rs` more than once"), "{error}");
Ok(())
}
Loading