URL:
  <https://savannah.gnu.org/bugs/?68624>

                 Summary: hardcopy corrupts UTF-8 multibyte characters
(non-BMP code points and combining sequences)
                   Group: GNU Screen
               Submitter: akandy1ame
               Submitted: Fri 21 Aug 2026 09:01:32 AM UTC
                Category: encoding
                Severity: 3 - Normal
                Priority: 5 - Normal
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Unlocked
                 Release: 5.0.2
           Fixed Release: None
         Planned Release: None
           Work Required: None


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Fri 21 Aug 2026 09:01:32 AM UTC By: akandy.1ame <akandy1ame>
When running screen in UTF-8 mode (defutf8 on / defencoding utf8) and dumping
the current screen or scrollback with `screen -X hardcopy <file>` (or the
`hardcopy -h` scrollback variant), characters above U+00FF are corrupted in
the output file. `file` misidentifies the resulting file as ISO-8859 text
instead of UTF-8 text, and hexdump shows multibyte UTF-8 sequences truncated
mid-sequence, immediately followed by unrelated bytes.

This reproduces for:
- non-BMP characters (e.g. U+1F642 emoji)
- combining character sequences

Root cause: in src/fileio.c, WriteFile()'s hardcopy/scrollback dump path
encoded each screen cell through putc_encoded(), which passed only the cell's
`image` byte to EncodeChar() without merging in the per-cell `font` byte. In
UTF-8 mode, that font byte holds the upper bits of the code point
(reconstructed elsewhere via `image | font << 8`, e.g. in src/mark.c's
copy-mode writer), so characters whose code point does not fit the low byte
lost information before encoding.

A related report from 2016 describes the same class of problem (hardcopy
producing ISO-8859-1 output under UTF-8/defutf8):
https://lists.gnu.org/archive/html/screen-devel/2016-02/msg00015.html

A patch is attached that replaces putc_encoded() with a line-oriented
put_line_encoded() mirroring src/mark.c's UTF-8 handling (reconstructing the
code point via `image | font << 8`, skipping UCS_HIDDEN placeholder cells, and
encoding through ToUtf8_comb()). Non-UTF-8 encodings continue to use
EncodeChar(), now with the font byte correctly merged in. The patch has been
built and verified with autoreconf/./configure/make, and hardcopy output was
confirmed byte-exact for Japanese text, a non-BMP emoji, and long combining
sequences, both before/after comparison against an unpatched build.

Tested against GNU screen 5.0.0/5.0.1/5.0.2 (src/fileio.c is unchanged across
these releases).






    _______________________________________________________
File Attachments:

Name: 0001-fileio-fix-hardcopy-scrollback-UTF-8-multibyte-corru.patch Size:
4.7KiB

<https://file.savannah.gnu.org/file/0001-fileio-fix-hardcopy-scrollback-UTF-8-multibyte-corru.patch?file_id=58888>



    AGPL NOTICE

These attachments are served by Savane. You can download the corresponding
source code of Savane at
https://savannah.gnu.org/source/savane-3714b1e43b4a88489946f83659ee54b2ea0ae4e8.tar.gz

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?68624>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/

Attachment: signature.asc
Description: PGP signature

Reply via email to