Re: nano hangs when pasting just a few characters
Benno Schulenberg <[email protected]>
| Newsgroups | gmane.editors.nano.devel |
|---|---|
| Message-ID | <[email protected]> |
Op 26-02-2025 om 04:52 schreef Doug Smythies: >> Thank you for the patch. It made no difference. I even tried a much bigger >> delay and several in between delays. Okay. Then please try this other patch, attached. > I found some other paste buffer sizes that FAIL, in addition to the 5 > characters already talked about. 85, 197, and 293 (there will be more, but > that is as far as I got). No need to try all kinds of different sizes. But what I'm curious about: it fails when pasting 5 bytes, but not when pasting 6 or 7? If not, what does the "Sequence of hex codes" look like for those pastes? (Because I would expect the end-of-paste escape sequence to be broken there too.) > If I use PuTTY instead of OpenSSH_for_Windows these buffer lengths work > fine, suggesting that the root issue is with the OpenSSH_for_Windows code. Yes, the root issue is the OpenSSH_for_Windows splitting an escape sequence. But... if PuTTY works fine, I would strongly suggest to just use that. > [...] > Sequence of hex codes: 33 34 35 36 37 38 39 30 31 32 33 34 35 > 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 > 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 > 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 > 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 > 32 33 1b 5b 32 30 31 > > Sequence of hex codes: 7e This seems to suggest that OpenSSH_for_Windows does notice the escape sequence, but thinks that something that starts with "[2" (5b 32) has two more bytes, where in fact it has three. I think the attached patch will catch and work around this issue. Benno
0001-input-avoid-hanging-on-a-mangled-bracketed-paste-in-.patch
(text/x-patch, 2.4 KB)
From 5376564e4818fd7095f7f9d203342c06cc3c7291 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg <[email protected]> Date: Tue, 25 Feb 2025 17:24:25 +0100 Subject: [PATCH] input: avoid hanging on a mangled bracketed paste in a different way Instead of recognizing a truncated end-of-paste sequence, notice that the final tilde (~) comes in alone and decide that this is wrong: a bracketed paste should be a large batch (or several batches) of bytes, not single bytes coming in one by one. When the latter happens, end the bracketed paste and display a warning, while discarding the byte that came in alone. This change was inspired by this report: https://lists.gnu.org/archive/html/nano-devel/2025-02/msg00001.html --- src/nano.c | 13 +++++++++++-- src/winio.c | 6 ------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/nano.c b/src/nano.c index b3f51e06..b72f2962 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1444,9 +1444,13 @@ void suck_up_input_and_paste_it(void) cutbuffer = line; while (bracketed_paste) { + size_t were_waiting = waiting_keycodes(); int input = get_kbinput(midwin, BLIND); - if (input == '\r' || input == '\n') { + /* If key codes come singly, something is wrong. */ + if (were_waiting == 0 && waiting_keycodes() == 0) + break; + else if (input == '\r' || input == '\n') { line->next = make_new_node(line); line = line->next; line->data = copy_of(""); @@ -1457,7 +1461,7 @@ void suck_up_input_and_paste_it(void) line->data[index++] = (char)input; line->data[index] = '\0'; } else if (input != BRACKETED_PASTE_MARKER) - beep(); + break; } if (ISSET(VIEW_MODE)) @@ -1465,6 +1469,11 @@ void suck_up_input_and_paste_it(void) else paste_text(); + if (bracketed_paste) { + statusline(ALERT, _("Broken paste")); + bracketed_paste = FALSE; + } + free_lines(cutbuffer); cutbuffer = was_cutbuffer; } diff --git a/src/winio.c b/src/winio.c index 2fff0d9e..f82eb27e 100644 --- a/src/winio.c +++ b/src/winio.c @@ -735,12 +735,6 @@ int convert_CSI_sequence(const int *seq, size_t length, int *consumed) bracketed_paste = FALSE; return BRACKETED_PASTE_MARKER; } - } else { - /* When invalid, assume it's a truncated end-of-paste sequence, - * in order to avoid a hang -- https://sv.gnu.org/bugs/?64996. */ - bracketed_paste = FALSE; - *consumed = length; - return ERR; } #endif break; -- 2.48.1
OpenPGP_signature.asc
(application/pgp-signature, 840 B)
-----BEGIN PGP SIGNATURE----- wsF5BAABCAAjFiEEFo5vQpe/16ea/USWUUu+Lrjhlh8FAme+8zkFAwAAAAAACgkQUUu+Lrjhlh8C Yg/+Oob9Gw/h0rL7cXlpma07k6TmDWk2J+Zb2bkaBnjUvU8IrD+iyjo2RPPfqNTTs+EISqKCiP/6 7qqCh+DTPM+LEVHu5gf1f9rBxHEiKA+jXPCLFIKOQdaop33SCOHrbRUF5zbe9eHaUKYavq3pgRIi JrT/8kjdX8dxqJG47PHs6BKl7pcnnU3T3flxFrjQknQoWuqFY85+RQX+oEOetN30HcX2iT5xj4pU pPELGwZNJqEIeJpaMDk4h/9f1qWeLy/q75tAslOVk5Z0DPgs6mVxvPO/f02IWyAs19FXTu5Q8/xK 4SCFQjEYotdwn502Xiakl+IqVlNQjNxn9//y7pwrBb3aVimMzB5kJ7T7ovWRAXIlAzzPKieRuCap PolbXitrRP2/pVXHsEB+WyycEFa34KzXuoKWZpvul0SfjuEZs4JWfN1XVCZ5cNAQ+ty3Sy4C6HRy mpAdzGod3yTVoAGOexF9sHRYdyS/EK+W3ITWNh94gtN4YxAMJZnysNsH9Xi39T2nnqX1888pwHWY JXwsC2zKIQZvNSsFSjbz9Is+3naFyXsMUuMIX9/mQGpYmh+PS4MKJ2IbOKNI90tWgglbwMXGsFnW wz5Tui8ggRWECArtkG0/Y7hC6/5AI1KSDxtg5pLk3V7wOiqSEHOCRCHkqTc0PK2hifLd9DxRwTkH XsM= =T+jW -----END PGP SIGNATURE-----