mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 11:48:30 +00:00
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:
parent
f7b4354283
commit
79034bd291
@ -166,7 +166,8 @@ impl Command {
|
|||||||
// [1]: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessa
|
// [1]: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessa
|
||||||
// [2]: https://devblogs.microsoft.com/oldnewthing/?p=41553
|
// [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
|
estimated_command_line_len > 1024 * 6
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user