fix(linker): prevent overflow when estimating CLI arg list length

This also updates the estimate on Windows of the length argument
list to `saturating_add` to avoid overflow.
This commit is contained in:
Weihang Lo 2025-03-12 20:58:56 -04:00
parent f7b4354283
commit 79034bd291
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7

View File

@ -166,7 +166,8 @@ impl Command {
// [1]: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessa
// [2]: https://devblogs.microsoft.com/oldnewthing/?p=41553
let estimated_command_line_len = self.args.iter().map(|a| a.len()).sum::<usize>();
let estimated_command_line_len =
self.args.iter().fold(0usize, |acc, a| acc.saturating_add(a.as_encoded_bytes().len()));
estimated_command_line_len > 1024 * 6
}
}