After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 764088 - fullwidth character backspace handled incorrectly in canonical mode + input mode IUTF8
fullwidth character backspace handled incorrectly in canonical mode + input m...
Status: RESOLVED NOTABUG
Product: vte
Classification: Core
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: VTE Maintainers
VTE Maintainers
Depends on:
Blocks:
 
 
Reported: 2016-03-23 16:25 UTC by Ray Song
Modified: 2016-05-08 20:07 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
a proof-of-concept patch (1.22 KB, patch)
2016-03-23 16:25 UTC, Ray Song
none Details | Review

Description Ray Song 2016-03-23 16:25:18 UTC
Created attachment 324599 [details] [review]
a proof-of-concept patch

If both of input mode ICANON and local mode IUTF8 are set, "\b" handler incorrectly moves the cursor one cell left when the character on the left is fullwidth.
Comment 1 Ray Song 2016-03-23 16:26:35 UTC
sorry, it should be "local mode ICANON and int mode IUTF8".
Comment 2 Ray Song 2016-03-23 16:27:04 UTC
sorry, it should be "local mode ICANON and input mode IUTF8".
Comment 3 Egmont Koblinger 2016-03-23 18:53:48 UTC
Just to be sure we're on the same page, what is your use case that triggers a bug?

I assume: You start e.g "cat", enter a CJK character (e.g. Ctrl+Shift+U 4000 Enter), then press backspace and expect the cursor to retreat by 2 positions. Am I right?

I don't think it's a bug in vte. A "\b" that is received by vte from the tty driver should always move the cursor back by 1 cell. This is also the behavior of all other terminals. I'm quite certain that the termios settings (e.g. ICANON) should not influence the meaning of an input character in any way.

It's a bug (missing feature) in the kernel's tty driver's ICANON mode that it doesn't take width into account, and when pressing a Backspace on the keyboard it erases one cell rather than two. Actually it outputs a "\b \b" (backspace space backspace) to ensure that the cell is visually erased, it should do it twice. The kernel already knows to do this on control characters, e.g. ^E.

The kernel also needs to properly track the column (via the width of the characters) to be able to handle TABs, and Backspaces over TABs too. And, of course, combining (zero-width) characters too.

Many years ago I sent a few patches to the Linux kernel. Unfortunately I had limited knowledge back then and patched the vt driver instead of the tty layer.
Comment 4 Ray Song 2016-03-24 04:10:41 UTC
The "cat" example you raised is exactly my use case.

I have confirmed that it should be a bug in the erase handler in the kernel's tty driver with the following commands:

vte
strace -e read,write -p $(pgrep -n vte) |& grep 5

# bash (readline) ~ICANON, two "\b"
write(5, "\177", 1)                     = 1
read(5, "\10\10\33[0m\33[0m \33[0m \10\10", 8176) = 18
...
# cat ICANON, one "\b"
write(5, "\177", 1)                     = 1
read(5, "\10 \10", 8176)                = 3


 I have a glance at the erase handler in the kernels' tty driver ( https://github.com/torvalds/linux/blob/master/drivers/tty/n_tty.c#L1047 ) and it seems that it does not handle fullwidth backspace in ICANON mode correctly.
Comment 5 Egmont Koblinger 2016-03-24 05:28:06 UTC
I'd love to see this issue fixed! Unfortunately I won't have time to work on it any time soon, nor does the benefit vs. required work ratio look too good.

If you make any progress, e.g. report it to the kernel folks, come up with a patch etc., please loop me in, and/or provide a link here, thanks!
Comment 6 Ray Song 2016-03-24 05:40:38 UTC
I've reported the bug on https://bugzilla.kernel.org/show_bug.cgi?id=115231 .
Thank you for your analysis!