Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: out of memory error after "edit-command-line"
- X-seq: zsh-workers 50472
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: linuxtechguy@xxxxxxxxx
- Cc: devs <zsh-workers@xxxxxxx>
- Subject: Re: out of memory error after "edit-command-line"
- Date: Fri, 12 Aug 2022 13:18:22 -0700
- Archived-at: <https://zsh.org/workers/50472>
- In-reply-to: <CA+rB6GLESuh=VAybFCg9RrTJ-C2_wQ8XUc4G6OGaEyEX=QRw9A@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CA+rB6GJLBv1uRauTnBAPihETrzox8wC1wXT8KsZ=J8r2y+qeMA@mail.gmail.com> <CA+rB6GLESuh=VAybFCg9RrTJ-C2_wQ8XUc4G6OGaEyEX=QRw9A@mail.gmail.com>
On Fri, Aug 12, 2022 at 8:41 AM Jim <linux.tech.guy@xxxxxxxxx> wrote:
>
> Tried to isolate what causes the 'out of memory' errors and found that if
> I added quotes the error stopped.
> CL=${(0A)"$(< /proc/$P/cmdline)"} # OK
> CL=${(0A)$(< /proc/$P/cmdline)} # out of memory error
I didn't reproduce the out-of-memory error with zsh-5.9-31, but I did
reproduce an infinite loop in wordcount() because skipwsep() does not
consider a metafied NUL byte to be whitespace. spacesplit() is
entered with e.g. 'zsh\203 -f\203 ' and calls wordcount() on the first
\203, which returns 2, then calls skipwsep() which returns without
skipping anything because iwsep(' '^32) is false, and around we go
again.
I think the OOM is related because spacesplit() will allocate memory
for each word that it believes it found, and the loop causes it to
keep finding empty words forever. With sufficient RAM it just takes
so long to use it all up that I give up waiting and kill the shell
with gdb, which is how I found the loop case.
However, I can't come up with a minimal test case to invoke the
initial condition. It's not enough just to do e.g.
${(0A)$(</proc/$$/cmdline)} in isolation.
Quotes matter because readoutput() does not call spacesplit() when
$(...) is quoted, but I don't know why extendedglob would make any
difference.
> But even so, should zsh ever fail with an 'out of memory' error?
There's really no way for the shell to know that it is imminently
going to run out of memory and no useful way to recover once it has
done so. Except in cases of bugs (which this appears to be), OOM only
results from a programming error on the part of the user.
Back to the original problem ... it appears that findsep(&s, NULL, 0)
considers '\203 ' to be a separator (because a null byte is in $IFS ?)
but skipwsep() does not. Can anyone else see why this doesn't break
in every case of splitting strings with embedded NUL ?
Messages sorted by:
Reverse Date,
Date,
Thread,
Author