Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Very long command string: wrong error message "219kB exceeds 2MB" #6800

Closed
mhansen opened this issue Mar 24, 2020 · 6 comments
Closed

Very long command string: wrong error message "219kB exceeds 2MB" #6800

mhansen opened this issue Mar 24, 2020 · 6 comments

Comments

@mhansen
Copy link

mhansen commented Mar 24, 2020

Just pulled fish from master: fish, version 3.1.0-424-gd0bedf3bb. uname -a is Linux markhansen 5.2.17-1rodete3-amd64 #1 SMP Debian 5.2.17-1rodete3 (2019-10-21 > 2018) x86_64 GNU/Linux

I'm running inside tmux with $TERM screen-256color, but I don't think that matters here.

I run a very long command (confidential work command, can't paste here, will try to get an obfuscated version that has the same error). And I get this error:

Failed to execute process '<redacted>'. Reason:
The total size of the argument and environment lists 219kB exceeds the operating system limit of 2MB.
Try running the command again with fewer arguments.

Running the command with fewer arguments is helpful, but saying that 219kB exceeds 2MB is incorrect (219kB < 2MB).

My guess is perhaps I have too many arguments, or one of the arguments is too long, rather than the total being too long.

@mhansen
Copy link
Author

mhansen commented Mar 24, 2020

> getconf ARG_MAX
2097152

@mhansen
Copy link
Author

mhansen commented Mar 24, 2020

When I strace the execve call, I get:

[pid 213838] execve(REDACTED, [REDACTED], 0x55db4f943900 /* 36 vars */) = -1 E2BIG (Argument list too long)

@mhansen
Copy link
Author

mhansen commented Mar 24, 2020

Here's a redacted version of the command that triggers this for me on Linux (won't repro on macOS) - should error the same for you. Same length, just replaced all letters/numbers with 'x's.

redacted.fish.txt

It's 216kB, far under the 2MB limit.

@mhansen
Copy link
Author

mhansen commented Mar 24, 2020

Just managed to bisect it with this little script that tries to run /bin/echo with repeated characters given as an argument, the problem comes with any argument of size 131072.

#!/usr/local/bin/fish
exec /bin/echo (head -c $argv < /dev/zero | tr '\0' '\141') > /dev/null
$ bisect -low 1 -high 1000000 './test.sh $X'
131072 NOT OK
131071 OK

@mhansen
Copy link
Author

mhansen commented Mar 24, 2020

Here's a stackoverflow mentioning that we're hitting the limit MAX_ARG_STRLEN: https://serverfault.com/a/844666/550492

Which is defined as PAGE_SIZE * 128:
https://github.com/torvalds/linux/blob/master/include/uapi/linux/binfmts.h#L15

@faho faho closed this as completed in 26c5181 Mar 24, 2020
@faho faho added this to the fish 3.2.0 milestone Mar 24, 2020
@mhansen
Copy link
Author

mhansen commented Mar 25, 2020

Fantastic, just pulled master and this works great!

> ./test.sh 1000000
Failed to execute process '/bin/echo'. Reason:
One of your arguments exceeds the operating system's argument length limit.
Try running the command again with fewer arguments.

I really appreciate your fast fix here @faho

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants