[Linux] DEBUG_PRINT_LAYOUT is left on in fl_keyboard_manager.cc; its loop looks up keycodes 0-7 and crashes on an X display without XKB (ssh -X)

Aperta Adatta ai principianti
#195,591 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
75/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
c
Ambito
backend, desktop

Direzione di ricerca

Leggi engine/src/flutter/shell/platform/linux/fl_keyboard_manager.cc, in particolare la definizione di DEBUG_PRINT_LAYOUT e il ciclo guarantee_layout() descritto nell’issue. Riproduci il problema con un display X non attendibile seguendo i passaggi forniti, poi verifica che la prima pressione di un tasto non provochi più un arresto anomalo quando il ciclo di debug è disabilitato o reso facoltativo.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

waiting for response
Steps to reproduce

On Linux, a Flutter app segfaults on its first key press when it runs as an untrusted X client, for example over ssh -X with OpenSSH's default ForwardX11Trusted no (the default on macOS). The same app works as a trusted client (ssh -Y).

Minimal repro on Ubuntu 22.04 or 24.04, Flutter 3.47.7 stable:

  1. flutter create --platforms=linux app
  2. In linux/runner/my_application.cc, call fl_dart_project_set_enable_impeller(project, FALSE); (so the software renderer works under Xvfb).
  3. flutter build linux --release
  4. Start an X server with the SECURITY extension and make an untrusted cookie:
    xauth -f t add :77 . $(mcookie)
    Xvfb :77 -auth t +extension SECURITY -noreset &
    XAUTHORITY=t xauth -f u generate :77 . untrusted timeout 3600
    
  5. Run the app as the untrusted client and type one key as a trusted one:
    DISPLAY=:77 XAUTHORITY=u FLUTTER_LINUX_RENDERER=software build/linux/x64/release/bundle/app &
    DISPLAY=:77 XAUTHORITY=t xdotool search --sync --onlyvisible --name app windowfocus --sync
    DISPLAY=:77 XAUTHORITY=t xdotool type a
    
Expected results

The key press reaches the app, as it does with XAUTHORITY=t (a trusted client).

Actual results

The app is killed by SIGSEGV in gdk_x11_keymap_lookup_key.

Cause: engine/src/flutter/shell/platform/linux/fl_keyboard_manager.cc line 19 has #define DEBUG_PRINT_LAYOUT, which has been on since flutter/engine#32665 (April 2022) and is still on in master. With it on, guarantee_layout() runs for (uint16_t keycode = 0; keycode < 128; keycode += 1), calling convert_key_to_char and so gdk_keymap_lookup_key() for keycodes 0 to 127 on the first key press of each group. It builds debug_layout_data, which is never printed.

X keycodes start at the display's min_keycode (8 here). With XKEYBOARD, GDK tolerates keycode 0. An untrusted client is not given XKEYBOARD, so GDK uses the core keymap, computes (0 - min_keycode) unsigned, and reads out of bounds.

Suggested fix: remove the #define (or make it opt-in). Optionally, convert_key_to_char could also skip keycodes outside the display's XDisplayKeycodes range.

Code sample

The stock flutter create app, with only the Impeller change in step 2.

Logs

Stack, Ubuntu 24.04, GTK 3.24.41-4ubuntu1.3, gdb with debuginfod:

#0  gdk_x11_keymap_lookup_key (keymap=GdkX11Keymap, key=0x7fffffffc840) at gdk/x11/gdkkeys-x11.c:1063
#1  libflutter_linux_gtk.so (guarantee_layout / convert_key_to_char, inlined)
#2  libflutter_linux_gtk.so (fl_keyboard_manager_handle_event path)
#3-#7  g_signal_emit key-press-event on FlView
#8  gtk_widget_event_internal (FlView)
#9  gtk_window_propagate_key_event
#10 gtk_window_key_press_event
#16-#19 gtk_widget_event_internal / propagate_event / gtk_main_do_event
#21 _gdk_event_emit
#23 gdk_event_source_dispatch
#24-#28 g_main_context_iteration / g_application_run
#29 main

At the crash: *key = {keycode = 0, group = 0, level = 0}, keymap min_keycode = 8, max_keycode = 255, keysyms_per_keycode = 7, xkb_desc = NULL, rax = 0xffffffc8 (that is (0 - 8) * 7). A breakpoint on gdk_keymap_lookup_key counts 354 calls on the first key: keycodes 0 to 127 at levels 0 and 1 (the debug loop) plus the 49 layout goals. The same crash happens on Ubuntu 22.04 (GTK 3.24.33).

Flutter Doctor output

Flutter 3.47.7 stable, engine d8a2d6c768, on Ubuntu 22.04 and 24.04 (GitHub Actions runners).

Lingua principale
Dart
Stelle
181k
Fork
33.3k
Merge medio
1g 20h
PR unite (30g)
281

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di flutter/flutter

Tutte le issue di flutter/flutter

Issue simili

Altre issue su Dart

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.