Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Bug: zsh crashed when completing with pattern



On Sun, Feb 22, 2026 at 8:28 AM Ma Rocket <ma2014119@xxxxxxxxxxx> wrote:
>
> I was writing completion script when I found zsh would crash on my `_arguments` argument.
> Here is the problematic line:
>
> '(-l --highlight)'{-l,--highlight}'[Byte to highlight]:*[:number:]+:HIGHLIGHTS INT: '
>
> The minimum completion script to reproduce: (filename: _sss)
>
> #compdef sss
>
> _arguments '-x[test]:*[:number:]:X: '
> EOF
>
> When press tab after `-x`, zsh crashed. I can predict that the pattern is the root cause.

Not exactly.  It's the parse of the _arguments argument that's at
fault.  Patch below fixes the core dump, but your _arguments syntax is
wrong.  The colons separate parts of the argument spec, so you need to
protect any that are part of the pattern.  The doc says

     Any literal colon in an OPTNAME, MESSAGE, or ACTION must be
     preceded by a backslash, '\:'.

That should also mention PATTERN.

_arguments '-x[test]:*[\:number\:]:X: '

Also, do you perhaps mean [[\:digit\:]] ?   In your original line
    [:number:]+
matches any of :,n,u,m,b,e,r followed by + (the patterns here aren't
regular expressions).

Note, I'm not 100% sure that the patched test for endpat shouldn't be
    (!endpat || pattry(endpat,line))
but it doesn't seem to make any difference.  Anyone?

diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index d9bf368d0..8e56f47a7 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -3865,8 +3865,8 @@ enditem()
 )
 enditem()

-Any literal colon in an var(optname), var(message), or var(action)
-must be preceded by a backslash, `tt(\:)'.
+Any literal colon in an var(optname), var(pattern), var(message), or
+var(action) must be preceded by a backslash, `tt(\:)'.

 Each of the forms above may be preceded by a list in parentheses
 of option names and argument numbers.  If the given option is on
diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c
index 55b0a9b9f..ccf2053f2 100644
--- a/Src/Zle/computil.c
+++ b/Src/Zle/computil.c
@@ -2115,7 +2115,7 @@ ca_parse_line(Cadef d, Cadef all, int multi, int first)

         if (state.def->type == CAA_REST || state.def->type == CAA_RARGS ||
         state.def->type == CAA_RREST) {
-        if (state.def->end && pattry(endpat, line)) {
+        if (state.def->end && endpat && pattry(endpat, line)) {
             state.def = NULL;
             state.curopt = NULL;
             state.opt = state.arg = 1;




Messages sorted by: Reverse Date, Date, Thread, Author