https://bugs.kde.org/show_bug.cgi?id=527162

            Bug ID: 527162
           Summary: FTP worker 6.31.0: MLSD listings ignore the remote
                    encoding, garbling non-UTF-8 filenames
    Classification: Frameworks and Libraries
           Product: frameworks-kio
      Version First unspecified
       Reported In:
          Platform: Arch Linux
                OS: Linux
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: FTP
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
  Target Milestone: ---

AI-assistance note: I used an AI assistant to help analyze the source code and
draft this report. I reproduced the bug myself, bisected it (kio 6.30.0 works,
6.31.0 broken), and verified every statement below before submitting.

DESCRIPTION

When the FTP server does not support UTF-8 (RFC 2640) — e.g. Serv-U serving
GBK/cp936 names and replying 502 to "OPTS UTF8 ON" — kio used to decode
directory listings with the configured remote encoding (Charset). Since kio
6.31.0, the new MLSD code path decodes the raw listing bytes with
QString::fromUtf8() instead, so filenames come out as U+FFFD replacement
characters.

In src/kioworkers/ftp/ftp.cpp, ftpReadDir() now contains:

    if (m_mlsdSupported) {
        // MLSD format: fact=value;fact=value; filename
        QString line = QString::fromUtf8(data).trimmed();
        ...
        de.name = line.mid(spaceIdx + 1);
        ...
        return true;
    }

This bypasses q->remoteEncoding()->decode(), which the older (LIST) parsing
path below it still uses correctly.

MLSD is also now preferred unconditionally whenever FEAT advertises MLST
(ftpOpenDir() / ftpQueryFeatures()), both added in 6.31.0.

With my server, remoteEncoding() correctly stays at the Charset=GBK that is
configured for that host in ~/.config/kio_ftprc (OPTS UTF8 ON is rejected
with 502), and the LIST path shows Chinese names correctly, but the MLSD
path shows "�" characters.

Bisected: kio 6.30.0 displays names correctly, 6.31.0 is broken; upstream
master still contains the bug (as of 2026-10-16).

STEPS TO REPRODUCE

1. Connect to an FTP server that serves non-UTF-8 (e.g. GBK) filenames and
   advertises MLST in FEAT, but does not support "OPTS UTF8 ON" (replies 502).
2. Set the correct charset for the host in ~/.config/kio_ftprc:
   [ftp.example.org]
   Charset=GBK
3. Open ftp://ftp.example.org/ in Dolphin (or list it with any KIO client).

OBSERVED RESULT

Directory entries with non-ASCII names are garbled and shown as U+FFFD
replacement characters; e.g. "使用说明.txt" is shown as "���˵���.txt".

EXPECTED RESULT

Filenames should be decoded with remoteEncoding() (the Charset configured
for the host), exactly like the LIST path does, so Chinese names display
correctly.

SOFTWARE/OS VERSIONS

Operating System: Arch Linux (aarch64)
KDE Plasma Version: 6.7.5
KDE Frameworks Version: 6.31.0
Qt Version: 6.12.0

ADDITIONAL INFORMATION

- Server: Serv-U FTP Server v14.0. FEAT lists "MLST
Type*;Size*;Create;Modify*;Perm;...".
  Raw MLSD output contains GBK bytes; "OPTS UTF8 ON" returns "502 Command not
implemented".
- MLSD listing support was introduced by commit fe8d690b
  (https://invent.kde.org/frameworks/kio/-/commit/fe8d690b, "workers/ftp:
implement
  proper file modification timestamps using RFC3659"), first released in
6.31.0.
- Suggested fix: decode the MLSD line with the remote encoding instead of
UTF-8:
      QString line = q->remoteEncoding()->decode(data).trimmed();
  (the facts are ASCII; only the filename part needs the remote encoding).
- Local workaround meanwhile: downgrade kio to 6.30.0.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to