Skip to content

SG-44961 Fix cp932 UnicodeDecodeError reading subprocess stderr on Japanese Windows - #367

Draft
stevelittlefish wants to merge 2 commits into
masterfrom
ticket/SG-44961-cp932-stderr-decode
Draft

SG-44961 Fix cp932 UnicodeDecodeError reading subprocess stderr on Japanese Windows#367
stevelittlefish wants to merge 2 commits into
masterfrom
ticket/SG-44961-cp932-stderr-decode

Conversation

@stevelittlefish

@stevelittlefish stevelittlefish commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Jira: SG-44961

Problem

On Japanese Windows, tk-framework-desktopserver crashes while reading a launched subprocess's stderr. Reported by SUBARU Corp. when opening a PSD from Flow Production Tracking with Photoshop 2026 (27.8) using a Japanese Photoshop UI. The same code is present unchanged on master, so this has effectively always been broken on non-utf-8 locales.

There are two distinct defects in command.py, both in _call_cmd_win32.

Bug 1 (trigger): the stdout/stderr temp files are read with no explicit encoding, so open() uses the OS locale codec, which is cp932 on Japanese Windows. Non-ASCII subprocess output (byte 0x97) then raises UnicodeDecodeError: 'cp932' codec can't decode byte 0x97.

Bug 2 (turns it into a crash): the win32 exception handler wrapped the traceback line list inside another list (stderr_lines = [traceback.format_exc().split()]), so "".join(stderr_lines) in call_cmd raised TypeError: sequence item 0: expected str instance, list found. The Unix path assigns the list directly and is correct.

Fix

Decode both temp files as utf-8 with errors="replace" so the reader never crashes regardless of what the DCC emits, and assign the traceback list directly in the win32 exception handler to match the Unix implementation.

Testing

Confirmed against the exact read/join logic: reading a stderr temp file containing byte 0x97 as cp932 raises UnicodeDecodeError inside the try, and the malformed handler then produces the TypeError seen in the customer log. With the fix, the same input decodes with a replacement character and does not crash.

QA reproduction recipe (Japanese system locale) is documented on the Jira ticket. English/Western Windows (cp1252) does not reproduce this because byte 0x97 is valid in cp1252.

…panese Windows

_call_cmd_win32 read the stdout/stderr temp files without an explicit
encoding, so open() used the OS locale codec (cp932 on Japanese Windows)
and raised UnicodeDecodeError on non-ASCII subprocess output. Decode both
files as utf-8 with errors="replace" so the reader never crashes.

Also fix the win32 exception handler, which wrapped the traceback line
list inside another list (stderr_lines = [traceback.format_exc().split()]),
causing "".join(stderr_lines) in call_cmd to raise
"TypeError: sequence item 0: expected str instance, list found". Match the
Unix implementation, which assigns the list directly.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codecov

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.09%. Comparing base (5db5ac0) to head (57971c5).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #367      +/-   ##
==========================================
+ Coverage   65.82%   66.09%   +0.26%     
==========================================
  Files          24       24              
  Lines        1870     1870              
==========================================
+ Hits         1231     1236       +5     
+ Misses        639      634       -5     
Flag Coverage Δ
Linux 47.54% <0.00%> (ø)
Python-3.10 66.09% <100.00%> (+0.26%) ⬆️
Python-3.11 66.09% <100.00%> (+0.26%) ⬆️
Python-3.13 65.98% <100.00%> (+0.26%) ⬆️
Python-3.9 66.05% <100.00%> (+0.26%) ⬆️
Windows 64.07% <100.00%> (+0.27%) ⬆️
macOS 64.34% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Covers both defects fixed in _call_cmd_win32:
- Bug 1: a subprocess emitting bytes undecodable by the OS locale codec
  (0x81 0xff, illegal under cp932/cp1252/utf-8) must not crash the reader.
- Bug 2: when the try block raises, the exception handler must leave
  stderr_lines as a flat list so call_cmd's "".join(...) does not raise
  TypeError.

Tests are skipped on non-Windows since the code path is Windows-only.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant