PIME icon indicating copy to clipboard operation
PIME copied to clipboard

Chewing silently stops working (keys swallowed) if the user config folder was created by an elevated PIMELauncher

Open checko opened this issue 1 month ago • 1 comments

Summary

If PIMELauncher.exe is ever started elevated (as Administrator), the Python backend creates %APPDATA%\PIME\<ime> with os.makedirs(..., mode=0o700). Since Python 3.12.4 (PIME bundles 3.12.9), mode=0o700 on Windows applies a restrictive DACL that grants access only to SYSTEM, Administrators and OWNER RIGHTS, and because the creating process is elevated, the folder owner becomes BUILTIN\Administrators instead of the user.

From then on, every normal (non-elevated) launcher, e.g. the one started at sign-in, cannot access the folder. For Chewing, chewing_new2() spends ~6 s retrying inside SQLite and then returns NULL. The text service then accepts every key and outputs nothing. Nothing is written to %LOCALAPPDATA%\PIME\Logs\python_backend.log.

Restarting the launcher from an elevated console "fixes" it, which makes the problem very hard to diagnose.

Environment

  • PIME 2.0.0-beta3, built from master @ b592d7a (2026-10-18)
  • Bundled Python 3.12.9 (32-bit)
  • Windows 11 Pro 10.0.26300, domain-joined account, only 新酷音 (chewing) enabled

Steps to reproduce

  1. Make sure %APPDATA%\PIME does not exist.
  2. From an elevated console, start PIMELauncher.exe and switch to 新酷音 in any app, so the backend creates %APPDATA%\PIME\chewing.
  3. Quit the launcher, then start it as the normal user (or sign out and in).
  4. Switch to 新酷音 in Notepad and type su3cl3.

Expected: 你好 is composed. Actual: nothing appears; keys are swallowed. The mode icon shows English.

Analysis

ACL of the folder created in step 2:

> icacls %APPDATA%\PIME\chewing
NT AUTHORITY\SYSTEM:(OI)(CI)(F)
BUILTIN\Administrators:(OI)(CI)(F)
OWNER RIGHTS:(OI)(CI)(F)
Owner: BUILTIN\Administrators

The user has no entry, so a non-elevated process (Administrators is deny-only in its filtered token) cannot open chewing.sqlite3.

Launcher debug log (/log-file): every onActivate takes ~6 s, the TSF client disconnects and reconnects, and replies arrive for clients that are already gone:

03:21:19.371688Z DEBUG Backend Input Raw: "...|{"isKeyboardOpen":true,"method":"onActivate","seqNum":12}"
03:21:25.282200Z DEBUG Backend Output Raw: "PIME_MSG|...|{... "icon": "...\\chewing\\icons\\eng.ico" ...}"
03:19:20.078026Z  WARN Received message for unknown client 74a4c568-...: {"return": true, ...}

Sampling the backend's main thread during onActivate shows it sleeping inside chewing.dll (SQLite's I/O-error retry loop):

ntdll!ZwDelayExecution <- KERNELBASE!SleepEx <- KERNELBASE!Sleep <- chewing.dll (+0x...)

Because chewing_new2() returns NULL and nothing checks it, get_ChiEngMode() and get_ShapeMode() return -1. filterKeyDown() then falls through to the Chinese-mode branch and returns True, and onKeyDown() feeds keys to a NULL context, so nothing is ever composed.

Fixing ownership and permissions resolves it immediately, without restarting anything:

icacls "%APPDATA%\PIME" /setowner "%USERDOMAIN%\%USERNAME%" /T
icacls "%APPDATA%\PIME" /reset /T

How the launcher ended up elevated

In my case it was my own install script, which started the launcher from the elevated session. The official NSIS installer already avoids this with ExecShellAsUser. Other ways it can still happen:

  • following the manual install steps in the README from an admin console;
  • running PIMELauncher.exe /console from an admin terminal while debugging.

Suggested fixes

  1. Don't create user folders with mode=0o700, or make sure the current user ends up as the owner / has an explicit ACE. Affected call sites:

    • python/server.py:35
    • python/input_methods/chewing/chewing_config.py:83
    • python/input_methods/rime/rime_ime.py:34
    • python/cinbase/config.py:96, cinbase/cin.py:376, cinbase/debug.py:24
    • python/cinbase/tools/cintojson.py:314, phrasetojson.py:66

    The profile folder is already private to the user, so the default inherited ACL seems enough.

  2. Fail loudly when chewing_new2() returns NULL (raise/log in ChewingContext.__init__), instead of running with a NULL context that silently swallows keys.

  3. Optionally, warn or de-elevate when PIMELauncher runs elevated, since the backend creates per-user files on behalf of the non-elevated user.


Reported by [email protected].

checko avatar Oct 20 '26 03:10 checko

This was generated by AI during triage. 【2026-11-11 驗證】提昇權限的 PIMELauncher 建立 0o700 設定夾、以及 NULL chewing context 靜默失靈,兩部分都由 merge b0257c6(PR #988)修妥;python/libchewing/libchewing.py:57-58 在 chewing_new2() 回傳 NULL 時直接 raise RuntimeError。 本機(Windows 11 ARM64,10.0.26300.9711,安裝版 2.0.0-beta4,SHA 2d160fe)以 python/python3/python.exe tests/run_worktree_tests.py tests/test_backend_resilience.py 對安裝目錄執行,結果 Ran 9 tests ... OK (skipped=1),exit 0;唯一跳過的是需要 librime 綁定的 rime 目錄清理測試。 EN: verified on the Windows box — the shipped 2.0.0-beta4 backend passes the 9-test resilience suite (the only skip is the librime-dependent prune test), and the null-context guard raises.

asdf80730 avatar Nov 10 '26 17:11 asdf80730