[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)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
阅读 engine/src/flutter/shell/platform/linux/fl_keyboard_manager.cc,尤其是 DEBUG_PRINT_LAYOUT 的定义和 issue 中描述的 guarantee_layout() 循环。按照提供的步骤,在不受信任的 X 显示环境中重现问题,然后检查禁用调试循环或将其设为可选后,首次按键是否不再导致崩溃。
由索引模型根据 Issue 内容生成。
描述
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:
flutter create --platforms=linux app- In
linux/runner/my_application.cc, callfl_dart_project_set_enable_impeller(project, FALSE);(so the software renderer works under Xvfb). flutter build linux --release- 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 - 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).
- 主要语言
- Dart
- 星标
- 181k
- 派生
- 33.3k
- 平均合并
- 1 天 19 小时
- 30 天内合并 PR
- 283
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
flutter/flutter 的其他 Issue
-
waiting for response
难度 2/5 1-3 小时 新手友好度 72/100
flutter/flutter#195626 · 1 条评论 ·
维护者通常 1 天内回复
-
a: accessibility has reproducible steps p: cupertino_ui package team-design
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
a: accessibility p: cupertino_ui package team-design
难度 2/5 1-3 小时 新手友好度 76/100
flutter/flutter#195514 · 1 条评论 ·
维护者通常 1 天内回复
-
SweepGradient.lerp clamps valid negative angles during interpolation可能已有人在做 @Shubham-Padkonde 于 3 天前认领。 未关闭a: animation c: rendering framework team-framework
难度 2/5 1-3 小时 新手友好度 77/100
flutter/flutter#195470 · 1 条评论 ·
维护者通常 1 天内回复
-
fyi-ecosystem has reproducible steps p: webview package platform-ios team-ios
难度 2/5 1-3 小时 新手友好度 76/100
flutter/flutter#195465 · 2 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 83/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 82/100
维护者通常 1 天内回复
-
good first issue help wanted
难度 2/5 1-3 小时 新手友好度 88/100
mollykitten/waveform#112 ·
维护者通常 1 天内回复
-
auto-implement-claude
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
Suwayomi/Suwayomi-Tsumiru#698 ·
维护者通常 1 天内回复