help / color / mirror / code / Atom feed
From: Alan Wagner-Krankel <awk@awkwork.com>
To: zsh-workers@zsh.org
Subject: zargs error with some combinations of arguments
Date: Thu, 18 Aug 2022 21:06:16 -0500	[thread overview]
Message-ID: <CAGZNKjKKfA3yS1HRBTgij1DtU0EB4OVx9GxsQq6i1=rnBUfUug@mail.gmail.com> (raw)

I've run across some conditions that apparently trip up calls to
zargs. A simplified example:

zsh -f <<\eof
  print count:${#vals} length:${(c)#vals}
  autoload -Uz zargs
  zargs -- $vals -- print -l

The output:
count:256 length:20479
zargs: cannot fit single argument within size limit

This error occurs when:
- the combined length of the arguments that are going to be used in a
  call is less than the max argument size (-s, default is 20480), and
- the length of the command string plus the arguments is greater than
  the -s size value.

It looks like zargs was set up this way to emulate the behavior of
gxargs from GNU findutils. With the right options, you can get a
similar error:

gxargs -L 256 -s 20480 -x echo <<<${(f)${(l:79::x:):-{001..256}}}

On my system this returns:
gxargs: argument list too long

I wasn't able to find an input that gave this result when using
the (large) defaults for gxargs.

On the other hand, POSIX seems to want the constructed command to fit
within all of the various size arguments, if I'm reading this snippet
in the spec correctly:
-s size
  Invoke utility using as many standard input arguments as possible
  yielding a command line length less than size (a positive decimal
  integer) bytes. Fewer arguments shall be used if:
  - The total number of arguments exceeds that specified by the -n
  - The total number of lines exceeds that specified by the -L option.

I've run into the zargs error a couple of times recently with
real-world data, so my system is now using a version that is hopefully
a bit closer to the POSIX behavior.  The diff listing is below.

Another option would have been to use a large value for -s, and
significantly reduce the likelihood of hitting a set of inputs that
result in an error.  That seems to be the gxargs approach.

Any thoughts? Is there something else I missed, or is a change like
I've described something that you want to consider for a future
version of zargs?

Thank you for reading this far. Hope I didn't make too many mistakes
in my first post to the list :).


diff --context=1 zsh.5.9/Functions/Misc/zargs ~/.zfunctions/zargs
*** zsh.5.9/Functions/Misc/zargs
--- ~/.zfunctions/zargs
*** 178,180 ****

! local -i end c=0
  if [[ $eof == -(e|-eof) ]]; then ((end=ARGC+1))
--- 178,180 ----

! local -i end a c=0
  if [[ $eof == -(e|-eof) ]]; then ((end=ARGC+1))
*** 249,250 ****
--- 249,257 ----

+ (( a = s - ${#:-"$command "} ))
+ if (( a <= 0 ))
+ then
+     print -u2 'zargs: value for max-chars must be >= command length'
+     return 1
+ fi
*** 291,293 ****
    ((ARGC)) || break
!   for (( end=l; end && ${(c)#argv[1,end]} > s; end/=2 )) { }
    (( end > n && ( end = n ) ))
--- 298,300 ----
    ((ARGC)) || break
!   for (( end=l; end && ${(c)#argv[1,end]} > a; end/=2 )) { }
    (( end > n && ( end = n ) ))

             reply	other threads:[~2022-08-19  2:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-19  2:06 Alan Wagner-Krankel [this message]
2022-08-22 21:31 ` Bart Schaefer
2022-08-23  4:39   ` Alan Wagner-Krankel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAGZNKjKKfA3yS1HRBTgij1DtU0EB4OVx9GxsQq6i1=rnBUfUug@mail.gmail.com' \
    --to=awk@awkwork.com \
    --cc=zsh-workers@zsh.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).