bugGNU nano - Bugs: bug #64996, nano hangs when 39 characters are...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #64996: nano hangs when 39 characters are pasted in a VScode terminal

Submitter:  Jacob Lifshay <programmerjake>
Submitted:  Thu 07 Dec 2023 11:03:58 PM UTC
   
 
Severity:  4 - Important Status:  Fixed
Assigned to:  bens Open/Closed:  Open

Jump to the original submission

Thu 21 Dec 2023 02:48:00 PM UTC, comment #13: 

Thanks for the feedback.  The mitigation has been pushed to git, commit 4a915b1e.  It avoids the hang by understanding any invalid escape sequence that starts with \e[2 as a truncated end-of-paste marker.

(Marked as "Fixed" because Savannah does not know "Worked-around".)

Benno Schulenberg <bens>
Group administrator
Thu 21 Dec 2023 09:59:13 AM UTC, comment #12: 

comment #11:

> comment #10:
> > it avoids hanging, but the text in nano's buffer after pasting is:
> > aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~
>
> Hm.  The spurious tilde isn't eaten?

yes, there's an extra tilde left over.

Are you positive that you applied file #55454 and not the earlier simpler patch?

yes. I checked out v7.2 and applied the patch.
git diff:
diff --git a/src/winio.c b/src/winio.c
<snip>
+                               /* Consume a delayed tilde -- see https://sv.gnu.org/bugs/?64996. */
+                               if (length == 3 && seq[2] == '1') {
<snip>

md5sum:
14ffe41ad70fa612fb8be9b53d1b6dea  src/winio.c

Jacob Lifshay <programmerjake>
Thu 21 Dec 2023 09:45:07 AM UTC, comment #11: 

comment #10:

> it avoids hanging, but the text in nano's buffer after pasting is:
> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~


Hm.  The spurious tilde isn't eaten?  Are you positive that you applied file #55454 and not the earlier simpler patch?

If the tilde-eating fragment doesn't work, then I can drop it from the patch.  Although a spurious tilde in the buffer isn't nice, it's much much better than hanging.

Benno Schulenberg <bens>
Group administrator
Tue 19 Dec 2023 01:18:15 AM UTC, comment #10: 

comment #9:

> Attached patch should avoid the hang and should consume the "spurious" trailing tilde.  Can you check whether this works?


it avoids hanging, but the text in nano's buffer after pasting is:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa~

> (Even when VScode starts to avoid splitting escape sequences, I think it's worth adding this patch to nano anyhow, for a little extra robustness, just in case.)


I agree.

Jacob Lifshay <programmerjake>
Fri 15 Dec 2023 11:07:51 AM UTC, comment #9: 

Attached patch should avoid the hang and should consume the "spurious" trailing tilde.  Can you check whether this works?

(Even when VScode starts to avoid splitting escape sequences, I think it's worth adding this patch to nano anyhow, for a little extra robustness, just in case.)

(file #55454)

Benno Schulenberg <bens>
Group administrator
Tue 12 Dec 2023 05:48:58 PM UTC, comment #8: 

vscode is apparently going to add a workaround where they try to avoid splitting escape sequences across multiple writes:
https://github.com/microsoft/vscode/issues/180257#issuecomment-1852380882

Jacob Lifshay <programmerjake>
Tue 12 Dec 2023 04:58:35 PM UTC, comment #7: 

Hmm.  When VScode always splits pastes into chunks of at most 50 bytes, then it's strange that nano receives pastes of 40 or 41 or 42 or 43 characters in one bunch.  All I can think of is that somehow ncurses notices that "1b 5b 32 30" is an incomplete escape sequence and waits for more to arrive, but does not notice that "1b 5b 32 30 31" is incomplete.  (Or maybe VScode sends a chunk quicker when it's more than one byte?  Just quick enough for ncurses to weld the chunks together.)

Attached patch should avoid nano's hang.  But it will leave a spurious "~" in the buffer for pastes of 39 characters (and probably for certain multiples too).

(file #55439)

Benno Schulenberg <bens>
Group administrator
Tue 12 Dec 2023 06:34:03 AM UTC, comment #6: 
Jacob Lifshay <programmerjake>
Tue 12 Dec 2023 04:05:08 AM UTC, comment #5: 

comment #4:

> It seems as though vscode just likes being weird when pasting 39-character strings...


It appears I was wrong, vscode does split pasted strings into 50-byte sections.

I made a simple test program that sets the terminal to raw mode, enables bracketed paste, and dumps the bytes it reads from the input. I then ran (in a separate terminal emulator):

(s=""; for i in {1..100}; do s+=a; echo "$i"; echo -n "$s" | xclip -i -selection clipboard; xdotool search --name 'VSCodium' windowactivate key Ctrl+V; sleep 0.1; done)

and then typed `exit` in the vscode terminal.

Hopefully, this is helpful...

(file #55436, file #55437)

Jacob Lifshay <programmerjake>
Tue 12 Dec 2023 03:01:58 AM UTC, comment #4: 

It seems as though vscode just likes being weird when pasting 39-character strings...

comment #3:

> When looking at the code, it seems the same hang should occur when pasting 40 or 41 or 42 characters.  Can you confirm?  I'm unsure what happens for 43 characters -- I think it should work right, but can you check?


nano doesn't hang when pasting 40-43 characters, they seem to get pasted as one write operation (or at least nano reports them on one log line)...

>
> Whether or not the above pastes hang, can you attach the debug results for a 40-character and for a 43-character paste?  Say, as TRAIL40 and TRAIL43.
>
> Also, when nano hangs after a paste, I think you can get out of the hang by following up with a short paste of just a few characters (the number should not matter, as long as it are fewer than 39).  Can you confirm this?


yes, I got out of the hang by pasting a 1-character string. it left the following text in nano's buffer:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1~a

(file #55434, file #55435)

Jacob Lifshay <programmerjake>
Sat 09 Dec 2023 11:34:24 AM UTC, comment #3: 

It seems that the VScode terminal sends at most 50 bytes in one go, which means that for a 39-character paste it chops the closing sequence of the bracketed paste into "\e [ 2 0 1" (in the first 50 bytes) and "~" (arriving in the next batch).  But nano expects to receive escape sequences in their entirety.  This is a deficiency in nano's keyboard handling, but would be difficult to fix.

When looking at the code, it seems the same hang should occur when pasting 40 or 41 or 42 characters.  Can you confirm?  I'm unsure what happens for 43 characters -- I think it should work right, but can you check?

Whether or not the above pastes hang, can you attach the debug results for a 40-character and for a 43-character paste?  Say, as TRAIL40 and TRAIL43.

Also, when nano hangs after a paste, I think you can get out of the hang by following up with a short paste of just a few characters (the number should not matter, as long as it are fewer than 39).  Can you confirm this?

Benno Schulenberg <bens>
Group administrator
Fri 08 Dec 2023 10:08:29 PM UTC, comment #2: 

I tested with nano-7.2 (I had to manually git pull --unshallow in gnulib for it to see the commit it wanted...)
it doesn't say Unknown Sequence, but the terminal and/or nano still seem to freeze.

When removing the #ifdef, nano still sees keys I type (it prints "Sequence of hex codes:") but doesn't do anything else.

the attached TRAIL file just contains the pasted sequence, without my later attempts at getting nano to do stuff after pasting.

(file #55422)

Jacob Lifshay <programmerjake>
Fri 08 Dec 2023 11:05:11 AM UTC, comment #1: 

In the linked issue, nano-4.8 is used.  Does the problem also occur when using the latest nano-7.2?

If yes, then please search for "hex codes" (without the quotes) in src/winio.c, remove the #ifdef around that fragment of code, compile, then run `src/nano 2>TRAIL`, do the offending paste, and attach here the resulting TRAIL file.  Because I'm curious what this "Unknown sequence" is -- it should not occur when simply pasting something into nano.

Benno Schulenberg <bens>
Group administrator
Thu 07 Dec 2023 11:03:58 PM UTC, original submission:  

issue on vscode's issue tracker: https://github.com/microsoft/vscode/issues/180257

Steps to Reproduce:

1. Launch VSCode on an Ubuntu computer (or on Windows using WSL)
2. Enter the built-in terminal
3. Run the command nano
4. Copy and paste the following 39-character string into nano: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Result: nano shows the error message "Unknown Sequence". Can no longer interact with the terminal, need to kill it and open a new one

Jacob Lifshay <programmerjake>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #55436:  dump-term-input.py added by programmerjake (476B - text/x-python)
file #55437:  keystrokes.txt added by programmerjake (9KiB - text/plain)
file #55434:  TRAIL40 added by programmerjake (295B - application/octet-stream)
file #55435:  TRAIL43 added by programmerjake (307B - application/octet-stream)
file #55422:  TRAIL added by programmerjake (279B - application/octet-stream - requested TRAIL file)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bens (Posted a comment)
  • -email is unavailable- added by programmerjake (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 14 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-01-23 bens Severity3 - Normal 4 - Important
        SummaryVScode terminal hangs when pasting 39 characters into nano nano hangs when 39 characters are pasted in a VScode terminal
    2023-12-21 bens SummaryVScode terminal hangs when pasting 39-characters into nano VScode terminal hangs when pasting 39 characters into nano
    2023-12-21 bens StatusNeed Info Fixed
        Assigned toNone bens
    2023-12-15 bens Attached File- Added 0001-input-avoid-hanging-after-a-39-character-paste-on-a-.patch, #55454
    2023-12-12 bens Attached File- Added avoid-hanging-on-certain-pastes.patch, #55439
    2023-12-12 programmerjake Attached File- Added dump-term-input.py, #55436
        Attached File- Added keystrokes.txt, #55437
    2023-12-12 programmerjake Attached File- Added TRAIL40, #55434
        Attached File- Added TRAIL43, #55435
    2023-12-08 programmerjake Attached File- Added TRAIL, #55422
    2023-12-08 bens StatusNone Need Info
        Summaryvscode terminal appears to crash when pasting 39-characters into nano VScode terminal hangs when pasting 39-characters into nano

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code