This issue was exposed when running postgres /bin/psql
with a super long
input (>130KB), the error was:
1 | fork/exec /bin/psql: argument list too long |
In Linux, the arugment total combined size is usually managed by kernal limit, a system defined constant, it can vary by system:
1 | # Byte: 2097152 => 2MB by default |
While ARG_MAX
defines the total combined size of all arguments and environment
variables passed to a new process, MAX_ARG_STRLEN
defines the maximum length
of a single argument or environment variable string.
MAX_ARG_STRLEN
is typically defined in the kernel headers, specifically in
linux/binfmts.h
. For many Linux systems, it’s defined as (PAGE_SIZE * 32)
1 | # MAX_ARG_STRLEN for single argument limit, unit: Byte: 131072 => 128KB |
How to Reproduce The Error
It is simple to trigger the limit error, for example:
1 | # create a random file with 129KB size |
How to Bypass
The possible solution to bypass the limit is to use pipe or filename as the input for the binary, for example:
1 | # Create a 500KB file as fake query (OS limit 128KB): |