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

Re: [bug] busy loop and memory exhaustion on {x..$'\80'} with nomultibyte



> 2022/09/25 19:34, Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
> 
> Thanks that's better, but now:
> 
> $ echo $options[multibyte]
> off
> $ printf %s {$'\x80'..$'\xff'} | hexdump -C
> 00000000  5c 4d 2d 5e 40 5c 4d 2d  5e 41 5c 4d 2d 5e 42 5c  |\M-^@\M-^A\M-^B\|
> 00000010  4d 2d 5e 43 5c 4d 2d 5e  44 5c 4d 2d 5e 45 5c 4d  |M-^C\M-^D\M-^E\M|
(snip)
> 
> That's bytes 0x80 to 0x9f with their \M-^X representation followed by UTF-8
> encoded (in my locale using UTF-8 as charmap) characters U+00A0 to U+00FF
> instead of bytes 0x80 to 0xff which I'd expect with nomultibyte.

Did you try 'LANG=C; setopt print_eight_bit' ?

Anyway, I will push the patch (included below again) with a test.

diff --git a/Src/utils.c b/Src/utils.c
index 62bd3e602..edf5d3df7 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -5519,7 +5519,7 @@ mb_metacharlenconv(const char *s, wint_t *wcp)
     if (!isset(MULTIBYTE) || STOUC(*s) <= 0x7f) {
 	/* treat as single byte, possibly metafied */
 	if (wcp)
-	    *wcp = (wint_t)(*s == Meta ? s[1] ^ 32 : *s);
+	    *wcp = (wint_t)STOUC(*s == Meta ? s[1] ^ 32 : *s);
 	return 1 + (*s == Meta);
     }
     /*
diff --git a/Test/D09brace.ztst b/Test/D09brace.ztst
index 580ed430f..c289be949 100644
--- a/Test/D09brace.ztst
+++ b/Test/D09brace.ztst
@@ -116,3 +116,10 @@
   print -r {1..10}{..
 0:Unmatched braces after matched braces are left alone.
 >1{.. 2{.. 3{.. 4{.. 5{.. 6{.. 7{.. 8{.. 9{.. 10{..
+
+  () {
+    setopt localoptions no_multibyte
+    echo -E {$'\x80'..$'\x81'}
+  }
+0:range of 8bit chars, mulibyte option unset
+>\M-^@ \M-^A





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