Skip to content

Commit 94eb03b

Browse files
committed
feat: fixed overflow crash
1 parent 964e8fc commit 94eb03b

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

src/gui/app.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -790,16 +790,18 @@ impl CollapseApp {
790790
let path = PathBuf::from(&settings.path);
791791

792792
let threads: usize = settings.threads.parse().unwrap_or(0);
793+
let mut builder = rayon::ThreadPoolBuilder::new().stack_size(8 * 1024 * 1024); // 8MB stack size
794+
793795
if threads > 0 {
794-
let res = rayon::ThreadPoolBuilder::new()
795-
.num_threads(threads)
796-
.build_global();
797-
if let Err(e) = res {
798-
let msg = format!("{}", e);
799-
if msg.contains("already been initialized") || msg.contains("already initialized") {
800-
} else {
801-
return Err(format!("Failed to configure threads: {}", e));
802-
}
796+
builder = builder.num_threads(threads);
797+
}
798+
799+
let res = builder.build_global();
800+
if let Err(e) = res {
801+
let msg = format!("{}", e);
802+
if msg.contains("already been initialized") || msg.contains("already initialized") {
803+
} else {
804+
return Err(format!("Failed to configure threads: {}", e));
803805
}
804806
}
805807

src/main.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ use {
1616
crate::types::{DetectionMode, FindingType, ScanResult, ScannerOptions},
1717
clap::Parser,
1818
colored::Colorize,
19+
serde_json::json,
1920
std::collections::HashMap,
2021
std::io::{self},
2122
std::path::{Path, PathBuf},
2223
walkdir::WalkDir,
23-
serde_json::json,
2424
};
2525

2626
#[cfg(all(feature = "cli", not(feature = "gui")))]
@@ -167,6 +167,8 @@ fn apply_env_overrides(args: &Args) {
167167

168168
#[cfg(all(feature = "cli", not(feature = "gui")))]
169169
fn configure_threading(args: &Args) -> Result<(), Box<dyn std::error::Error>> {
170+
let mut builder = rayon::ThreadPoolBuilder::new().stack_size(64 * 1024 * 1024);
171+
170172
if args.threads > 0 {
171173
if args.threads > 1024 {
172174
eprintln!(
@@ -175,10 +177,7 @@ fn configure_threading(args: &Args) -> Result<(), Box<dyn std::error::Error>> {
175177
args.threads
176178
);
177179
}
178-
rayon::ThreadPoolBuilder::new()
179-
.num_threads(args.threads)
180-
.build_global()
181-
.map_err(io::Error::other)?;
180+
builder = builder.num_threads(args.threads);
182181
if args.verbose {
183182
println!(
184183
"{} Using {} threads for processing.",
@@ -188,10 +187,12 @@ fn configure_threading(args: &Args) -> Result<(), Box<dyn std::error::Error>> {
188187
}
189188
} else if args.verbose {
190189
println!(
191-
"{} Using automatic number of threads (Rayon default).",
190+
"{} Using automatic number of threads (Rayon default) with increased stack size.",
192191
"🧵".blue()
193192
);
194193
}
194+
195+
builder.build_global().map_err(io::Error::other)?;
195196
Ok(())
196197
}
197198

@@ -370,7 +371,7 @@ fn run_cli() -> Result<(), Box<dyn std::error::Error>> {
370371

371372
let scanner = CollapseScanner::new(options.clone())?;
372373
let path = validate_and_prepare_path(&args)?;
373-
374+
374375
if !args.json {
375376
print_scan_configuration(&path, &args, &scanner);
376377
println!(
@@ -392,9 +393,9 @@ fn run_cli() -> Result<(), Box<dyn std::error::Error>> {
392393
if args.json {
393394
let mut sorted_significant_results = significant_results.clone();
394395
sorted_significant_results.sort_by_key(|r| &r.file_path);
395-
396+
396397
let (avg_danger_score, _, risk_level) =
397-
calculate_scan_score(&sorted_significant_results);
398+
calculate_scan_score(&sorted_significant_results);
398399

399400
let total_findings: usize = sorted_significant_results
400401
.iter()
@@ -409,7 +410,7 @@ fn run_cli() -> Result<(), Box<dyn std::error::Error>> {
409410
"score": avg_danger_score,
410411
"results": sorted_significant_results
411412
});
412-
413+
413414
println!("{}", serde_json::to_string_pretty(&json_output)?);
414415
return Ok(());
415416
}

0 commit comments

Comments
 (0)