Infinite loop triggered by extglob +(!(x))y
Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/bin' -DSTANDARD_UTILS_PATH='/usr/bin' -DSYS_BASHRC='/etc/bash.bashrc' -DSYS_BASH_LOGOUT='/etc/bash.bash_logout' -DNON_INTERACTIVE_LOGIN_SHELLS uname output: Linux charon.podzimek.org 5.12.15-arch1-1-zen2 #1 SMP PREEMPT Sun, 11 Jul 2021 10:50:03 + x86_64 GNU/Linux Machine Type: x86_64-pc-linux-gnu Bash Version: 5.1 Patch Level: 8 Release Status: release Description: An extglob like +(!(x))y causes Bash to freeze with a 100% CPU utilization. At the first glance the freeze doesn't seem to depend on the (non-)existence of matching paths. Repeat-By: echo +(!(x))y # This freezes! echo y+(!(x)) # Yet this does *not* freeze. echo +(!(x))* # And this does *not* freeze. echo *+(!(x)) # And this does *not* freeze.
Re: Infinite loop triggered by extglob +(!(x))y
On Sun, Jul 25, 2021 at 07:09:50PM +0200, andrej--- via Bug reports for the GNU Bourne Again SHell wrote: > Description: > An extglob like +(!(x))y causes Bash to freeze with a 100% CPU > utilization. > At the first glance the freeze doesn't seem to depend on the > (non-)existence of matching paths. The files do seem to matter. unicorn:~/tmp$ echo +(!(x))y servers-to-try unicorn:~/tmp$ cd /tmp unicorn:/tmp$ echo +(!(x))y ^C^C^ZKilled It's a really bad runaway, requiring SIGKILL from another terminal to stop it.
Re: Infinite loop triggered by extglob +(!(x))y
On Jul 25 2021, Greg Wooledge wrote: > On Sun, Jul 25, 2021 at 07:09:50PM +0200, andrej--- via Bug reports for the > GNU Bourne Again SHell wrote: >> Description: >> An extglob like +(!(x))y causes Bash to freeze with a 100% CPU >> utilization. >> At the first glance the freeze doesn't seem to depend on the >> (non-)existence of matching paths. > > The files do seem to matter. > > unicorn:~/tmp$ echo +(!(x))y > servers-to-try > unicorn:~/tmp$ cd /tmp > unicorn:/tmp$ echo +(!(x))y > ^C^C^ZKilled It depends on the length of the existing file names. That pattern has quadratic complexity. > It's a really bad runaway, requiring SIGKILL from another terminal to > stop it. Not really. It's just that an interactive shell ignores or postpones a lot of signals during command execution. In a non-interactive shell, a simple SIGINT will stop it. Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."
Re: Infinite loop triggered by extglob +(!(x))y
On 7/25/21 1:09 PM, andrej--- via Bug reports for the GNU Bourne Again SHell wrote: Bash Version: 5.1 Patch Level: 8 Release Status: release Description: An extglob like +(!(x))y causes Bash to freeze with a 100% CPU utilization. At the first glance the freeze doesn't seem to depend on the (non-)existence of matching paths. Repeat-By: echo +(!(x))y # This freezes! I can't reproduce this. This is a terribly inefficient pattern, and the behavior is proportional to the number of files and length of filenames. In the bash build directory, for instance, it fails right away, as it should: there aren't any files ending in `y'. In /tmp, with fewer files but longer filenames, it takes *much* longer. I agree that interactive shells could be more responsive to SIGINT. It's a question of checking for the flag the signal handler sets while executing the pattern matcher itself, rather than solely in the upper layers. This pattern spends a lot of time in a single call to strmatch(), which matches a single filename against a pattern, and the current code checks for SIGINT around calls to strmatch(). -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/
Re: Infinite loop triggered by extglob +(!(x))y
On Jul 25 2021, Chet Ramey wrote: > In the bash build directory, for instance, it fails right away, as it > should: there aren't any files ending in `y'. It doesn't matter whether the file name contains `y', just how long it is. Try creating a file with a name of 30 or more characters. Each additional character doubles the run time. Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."
Re: Infinite loop triggered by extglob +(!(x))y
On 7/25/21 5:01 PM, Andreas Schwab wrote: On Jul 25 2021, Chet Ramey wrote: In the bash build directory, for instance, it fails right away, as it should: there aren't any files ending in `y'. It doesn't matter whether the file name contains `y', just how long it is. That's not what I mean. It fails, as it should: there is no filename that will make it succeed. The runtime is obviously proportional to the length. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/