Comments (3)
Thanks for bringing this issue up - system specific limit is something I wasn't aware of before.
On Linux kernel, the length limitation of a single argument is indeed MAX_ARG_STRLEN
(131072) and this has never increased. You can test this easily with the following program:
#include <stdio.h>
#include <unistd.h>
#define LEN 131071
int main()
{
char s[LEN + 1];
int i;
for (i = 0; i < LEN; i++)
s[i] = 'x';
s[LEN] = 0;
return execl("/usr/bin/expr", "expr", "length", s, (char *)NULL);
}
Change LEN
to 131072
, the execl()
call shall fail.
Just like you doubted, your estimation of $TRANS_PROGRAM
isn't very correct. The actual lengths are 122233 and 122634 respectively, both did not exceed the MAX_ARG_STRLEN
limit on Linux.
$ git checkout 467a56
$ make &>/dev/null && . build/trans -V &> /dev/null && expr length "$TRANS_PROGRAM"
122634
$ git checkout HEAD~1
$ make &>/dev/null && . build/trans -V &> /dev/null && expr length "$TRANS_PROGRAM"
122233
While Linux kernel does check for validity of erch argument length (https://github.com/torvalds/linux/blob/master/fs/exec.c#L477), the OS X kernel, XNU, as well as other BSD derivatives, does not perform such check for each single argument, so there is no real equivalent to MAX_ARG_STRLEN
. XNU however, has a limitation on the maximum length of arguments, which is
#define ARG_MAX (256 * 1024) /* max bytes for an exec function */
as defined in <syslimits.h>
.
It may seem a bit weird that the argument of length 122233 is fine but the one of length 122634 crashes, since both are far less than 262144, even if you count in all other arguments 'gawk
', '-f
'. However, every OS has its quirks. I did a simple grepping into XNU's source, it seems these spaces are reserved not only for argv[]
, but also for envv[]
(http://www.opensource.apple.com/source/xnu/xnu-2782.1.97/bsd/kern/kern_exec.c , see L#3137-3330). I guess that's why we can't have a lengthier argument in its execve()
call.
(Not familiar with BSD implementation, so far it's really just a guess. Any experts?)
I cannot tell at exactly what length $TRANS_PROGRAM
could break on OS X; it is not solely about a single argument length, unlike Linux, as I explained above. Two straightforward solutions I can think of at the moment:
- Abandon the lengthy argument wrapping; use shell built-in
print
to pipe the whole program to gawk. (I bet shell can take infinite arguments, as long as it's not a system call) - Reduce the size of the core program and keep it to 100KB or below.
from translate-shell.
Thanks for the clarification; I didn't expect env vars to be counted against ARG_MAX
. Given that I'd go for shell builtins (yeah, as far as I know they are not limited by ARG_MAX
). Speaking of limiting the program size, it's still possible to exceed ARG_MAX
if a user in addition exports some long env vars (albeit unlikely).
from translate-shell.
Due fix in develop. Closing.
from translate-shell.
Related Issues (20)
- I can't use -play and -speak options together in the same time! HOT 2
- Add pot/po translation support
- 无法使用
- Add option to force retry if connection is lost
- Voice output unavailable
- -no-autocorrect doesn't work with Google translate HOT 2
- Stuck at getting output for RTL languages HOT 2
- Strange bug with some Chinese sentences containg : HOT 3
- gpg public key doesnt seems to be working HOT 1
- not reading .curlrc HOT 7
- Show target language on REPL mode HOT 3
- Space bar not working on REPL mode HOT 1
- sentence HOT 1
- Inconsistent inclusion of nikud in Hebrew results HOT 2
- Support socks proxy HOT 1
- Add ability to press "up arrow" on the keyboard to set the previous text, like in bash shell HOT 1
- "Voice output isn't available for English" HOT 6
- Separation '══════': now exists only for non-interactive mod, please add to the REPL (-I) also HOT 4
- gawk: fatal: can't open source file `/dev/fd/63' for reading (No such file or directory) HOT 6
- Support for recently added 110 new languages on Google Translate HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from translate-shell.