Fix iogate.getc input byte order shuffled bug#891
Open
tompng wants to merge 1 commit intoruby:masterfrom
Open
Conversation
When iogate.cursor_pos is called while handling signal inside iogate.getc, getc return bytes in wrong order. We need to always check `@buf` after `Reline.core.line_editor.handle_signal` is called.
Member
Author
|
Failed irb head ubuntu-latest job contains What happened is:
I'll fix IRB adding |
Member
Author
|
To make a similar situation, type this to IRB. Reproducible in Reline >= 0.6.1 Thread.new{
sleep 0.5;
stdin = Reline::IOGate.instance_eval{@input}
"\e[1;1R\e[2;2R".bytes.reverse_each{stdin.ungetc _1}
Process.kill :WINCH, $$;
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes this bug:

Sometimes, something like
"[10;16R"is input to reline, very rarely when a computer(macOS) wakes up from sleep mode, in Terminal.app. I think additional situation (external display triggers WIHCN) is needed to reproduce.Here's a timeline of a situation that this bug happens. (found by inserting many debug log output to ansi.rb)
IOGate.getcIOGate.cursor_posis called for each WINCH signal. Reline sends"\e[6n"(CPR, Cursor Position Request) and waits for0.5seccursor_postimed outcursor_postimed outcursor_posreceives"\e[1;1R\e[2;2R"(response to the first and second CPR)"\e[1;1R"and put"\e[2;2R"to@buf"\e", the leading byte of"\e[3;3R"(response to the third CPR)"\e\e[2;2R", resolved to ALT_KEY + unbound CSI escape sequence"3;3R", resolved to normal ascii key inputInput to Reline is
"\e[1;1R\e[2;2R\e[3;3R"but Reline thinks the input is"\e[1;1R\e\e[2;2R[3;3R".Fix: Always check
@buf.empty?after callingReline.core.line_editor.handle_signal