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 730220 - Doesn't properly update display after cating binary stuff
Doesn't properly update display after cating binary stuff
Status: RESOLVED FIXED
Product: vte
Classification: Core
Component: general
0.36.x
Other Linux
: Normal normal
: ---
Assigned To: VTE Maintainers
VTE Maintainers
Depends on:
Blocks:
 
 
Reported: 2014-05-15 22:00 UTC by Egmont Koblinger
Modified: 2014-05-17 11:48 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
test file 'socat' (8.00 KB, application/octet-stream)
2014-05-15 22:59 UTC, Egmont Koblinger
  Details
The Fix (2.71 KB, patch)
2014-05-16 01:37 UTC, Egmont Koblinger
none Details | Review
The Fix v2 (4.86 KB, patch)
2014-05-16 12:27 UTC, Egmont Koblinger
committed Details | Review

Description Egmont Koblinger 2014-05-15 22:00:21 UTC
- Download and uncompress the binary file "socat" from https://bugs.kde.org/show_bug.cgi?id=334432
- Start vte or g-t
- execute "cat socat"
- wait until completes (stops), note: you may not see the prompt because some of the escape sequences caused data to be injected as if it was typed
- press ^C to drop that data, the prompt appears
- execute "konsole --version", and repeat this step if necessary

In about half of the cases, three lines (qt, kde, konsole version) are printed and the prompt correctly appears.

In the other half of the cases, nothing seems to happen, as if konsole hung. However, any keypress (even a backspace) or dragging the scrollbar causes konsole's output and the prompt to appear.
Comment 1 Egmont Koblinger 2014-05-15 22:07:26 UTC
If you redirect the output: "konsole --version > /tmp/konsoleversion", you'll still face the vte bug: the prompt is not always displayed. If you check the output file's timestamp and content (it's recent and contains the full version info) and ps for konsole (it's not running) you'll find that konsole has already completed its task and quit.

If you make your bash prompt store the timestamp somewhere (e.g. PS1='blahblah $(date > /tmp/xx) blah'), you'll see that bash has already printed the new prompt, it's just not shown by vte.

If you execute "cat /tmp/konsoleversion", vte always updates the display correctly. However, something like "sleep 0.05; cat /tmp/konsoleversion" sometimes triggers the bug. So timing does matter a lot.

Even simpler test case: just execute "sleep 0.05", sometimes the prompt doesn't appear.
Comment 2 Egmont Koblinger 2014-05-15 22:10:31 UTC
When the bug occurs, highlighting the last (empty) line with mouse doesn't change anything. So it's not a display update, it's probably that vte hasn't even processed that incoming data.
Comment 3 Egmont Koblinger 2014-05-15 22:59:12 UTC
Created attachment 276632 [details]
test file 'socat'

Here's a smaller test file, cut out from the original. A few random bytes at the beginning, then the rest is ascii words separated by '\0'.

I'm not able to cut its size to below 8KB. (Well, a tiny little bit under 8KB, but with shell prompt and so on it probably exceeds that limit.) It's at least suspicious. I hope we're not dealing with another kernel bug/limitation as in bug 539312.
Comment 4 Egmont Koblinger 2014-05-15 23:38:21 UTC
Hmmm, seems like it has something to do with the UTF-8 decoder.

The first byte of a multibyte sequence, followed by NUL, followed by ~8K normal ascii characters triggers the bug:

echo -ne '\xC0\x00'; for i in {5..9000..5}; do printf %5s $i; done

The first 2 bytes, and the next 8174 bytes seem to get swallowed, the rest is printed ("5 8180 8185 8190 8195 8200 [...]") and the buggy behavior starts.

But a bug in the decoder wouldn't explain how dragging the scrollbar can have any effect on the terminal's contents. Weird...
Comment 5 Egmont Koblinger 2014-05-15 23:50:07 UTC
Correcting myself: keyboard input does *not* fix the display.

In case of an invisible bash prompt, pressing backspace fixed the display because bash rang the bell. Placing "set bell-style none" in .inputrc changes backspace not to fix the display.

Similarly, "sleep 0.05; echo foo; cat" sometimes doesn't display "foo", in that case backspace doesn't repair the screen. "sleep 0.05; passwd" sometimes doesn't show the pw changing instructions, and then you can type your old password without the display being updated.
Comment 6 Egmont Koblinger 2014-05-16 01:37:12 UTC
Created attachment 276640 [details] [review]
The Fix

Okay, so as it turns out, g_utf8_validate() and g_utf8_get_char_validated() don't handle the NUL byte properly.

Here's a fix. I'll double check it tomorrow, write unittests etc.
Comment 7 Egmont Koblinger 2014-05-16 12:27:05 UTC
Created attachment 276667 [details] [review]
The Fix v2

Fix, 2nd version. Bit of cleanup, unittests.