Skip to content

endstone_ubackup fails to backup files with surrogate pair characters in filenames #1

@chenwang05

Description

@chenwang05

问题描述

使用 endstone_ubackup 插件备份基岩版服务器世界时,备份线程崩溃,抛出 UnicodeEncodeError 异常,无法完成备份。

复现步骤

  1. 创建名称包含 Unicode 代理对字符的世界或文件(如部分 emoji、生僻 CJK 字符等非 BMP 字符)。
  2. 执行 endstone_ubackup 插件的备份功能。
  3. 查看服务器日志,观察到异常报错。

实际结果

备份线程崩溃,触发两次 UnicodeEncodeError,无法将文件写入 ZIP 压缩包。

错误日志

Exception in thread Thread-723 (on_backup_thread):
Traceback (most recent call last):
File "/usr/lib/python3.13/zipfile/init.py", line 519, in _encodeFilenameFlags
return self.filename.encode('ascii'), self.flag_bits
UnicodeEncodeError: 'ascii' codec can't encode characters in position 4-24: ordinal not in range(128)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.13/threading.py", line 1043, in _bootstrap_inner
self.run()
File "/usr/lib/python3.13/threading.py", line 994, in run
self._target(*self._args, **self._kwargs)
File "/home/cw/bedrock_server/plugins/.local/local/lib/python3.13/dist-packages/endstone_ubackup/ubackup.py", line 327, in on_backup_thread
zipf.write(file_path, os.path.relpath(file_path, worlds_file_path))
File "/usr/lib/python3.13/zipfile/init.py", line 1907, in write
with open(filename, "rb") as src, self.open(zinfo, 'w') as dest:
File "/usr/lib/python3.13/zipfile/init.py", line 1642, in open
return self._open_to_write(zinfo, force_zip64=force_zip64)
File "/usr/lib/python3.13/zipfile/init.py", line 1753, in _open_to_write
self.fp.write(zinfo.FileHeader(zip64))
File "/usr/lib/python3.13/zipfile/init.py", line 509, in FileHeader
filename, flag_bits = self._encodeFilenameFlags()
File "/usr/lib/python3.13/zipfile/init.py", line 521, in _encodeFilenameFlags
return self.filename.encode('utf-8'), self.flag_bits | _MASK_UTF_FILENAME
UnicodeEncodeError: 'utf-8' codec can't encode characters in position 4-24: surrogates not allowed

环境
Python版本:Python 3.13.5
endstone版本:0.11.2
插件版本:latest
操作系统:debian 13

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions