sharkdp / argmax Goto Github PK
View Code? Open in Web Editor NEWRust library to deal with "argument too long" errors
License: Apache License 2.0
Rust library to deal with "argument too long" errors
License: Apache License 2.0
Command
s inherit the parent's environment variables by default. Right now we check the size of the environment when you create a Command
, but it can be modified in the meantime:
#[test]
fn test_env() {
let mut cmd = Command::new("/bin/echo");
// Add as many arguments as possible
while cmd.try_arg("foo").is_ok() {}
for i in 0..1024 {
std::env::set_var(format!("VAR{i}"), "VALUE");
}
assert!(cmd.status().unwrap().success());
}
test tests::test_env ... FAILED
failures:
---- tests::test_env stdout ----
thread 'tests::test_env' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 7, kind: ArgumentListTooLong, message: "Argument list too long" }', src/lib.rs:204:30
We can document that std::env::set_var()
invalidates the calculations I guess. But we'll still have to think about this to implement try_env()
if we want it.
This is the current state (copied from sharkdp/fd#410)
fd
-supported platforms
*reasonably close: it shouldn't be an order of magnitude smaller than the actual limit.
Continuing the discussion from sharkdp/fd#410 (comment)
The actual argv
/envp
pointer are counted in units of size_of::<*const c_char>()
:
Lines 50 to 54 in 51575d7
But this is wrong if a 32-bit program is launching a 64-bit one on a 64-bit kernel. This leads to this failure: https://github.com/sharkdp/argmax/runs/4231259608?check_suite_focus=true. It can be reproduced locally with
$ rustup target add i686-unknown-linux-gnu
$ cargo test --target=i686-unknown-linux-gnu
...
Trying execution with 260638 args
thread 'can_run_command_with_maximum_number_of_arguments' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 7, kind: ArgumentListTooLong, message: "Argument list too long" }', tests/main.rs:49:30
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
A conservative fix would be to assume that pointers are at least 8 bytes wide on all platforms. Ideally we'd only do this on 64-bit kernels, but I don't know a good way to detect that from userspace.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.