Skip to content

Auto-detect and convert GBK-encoded archive filenames to UTF-8#24

Merged
vlssu merged 3 commits into
developfrom
copilot/fix-gbk-conversion-issue
Jan 19, 2026
Merged

Auto-detect and convert GBK-encoded archive filenames to UTF-8#24
vlssu merged 3 commits into
developfrom
copilot/fix-gbk-conversion-issue

Conversation

Copy link
Copy Markdown

Copilot AI commented Jan 19, 2026

Windows applications in China commonly create ZIP files with GBK-encoded filenames instead of UTF-8, causing extraction to fail with garbled filenames like open [�����]��Ȼ����v1.2: invalid argument.

Changes

  • Added decodeFilename() helper: Detects encoding using UTF-8 validation—if invalid, decodes as GBK; otherwise passes through unchanged
  • Integrated into extraction pipeline: Applied to f.NameInArchive before path construction in extractStream()
  • Added test coverage: Created test-gbk.zip with GBK-encoded Chinese filenames and corresponding tests

Implementation

func decodeFilename(filename string) string {
    if utf8.ValidString(filename) {
        return filename  // UTF-8 or ASCII
    }
    decoded, err := simplifiedchinese.GBK.NewDecoder().String(filename)
    if err != nil {
        return filename  // Failsafe
    }
    return decoded  // GBK → UTF-8
}

Applied at extraction:

decodedName := decodeFilename(f.NameInArchive)
p := filepath.Join(opts.Directory, decodedName)

This handles UTF-8, GBK, and ASCII filenames transparently without configuration.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • emperror.dev
    • Triggering command: /update-job-proxy /update-job-proxy -trimpath= -nolocalimports ux_amd64/vet go_.�� x64/src/net 8925888/b129/ ux_amd64/vet -p weak -lang=go1.24 ux_amd64/vet 8925�� g_.a -I x64/pkg/tool/linux_amd64/vet --gdwarf-5 g/x/sys/cpu -o x64/pkg/tool/linux_amd64/vet (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy -o br-7e8f4456b9ff -j DROP REDACTED 18885ac2:go.mod e/git-remote-https ock fa09c952e3eadbffcat-file /bin/git e/git-remote-httc2b33e8439af944379acbdd9c3a5fe0bc44bd8a5:go.mod fetc�� om/smartystreets/go-aws-auth origin /bin/git refs/tags/*:refs/usr/sbin/iptables riter/go.mod ps /usr/bin/git (dns block)
  • go.googlesource.com
    • Triggering command: /update-job-proxy /update-job-proxy -trimpath= -nolocalimports ux_amd64/vet go_.�� x64/src/net 8925888/b129/ ux_amd64/vet -p weak -lang=go1.24 ux_amd64/vet 8925�� g_.a -I x64/pkg/tool/linux_amd64/vet --gdwarf-5 g/x/sys/cpu -o x64/pkg/tool/linux_amd64/vet (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy -o br-7e8f4456b9ff -j DROP REDACTED 18885ac2:go.mod e/git-remote-https ock fa09c952e3eadbffcat-file /bin/git e/git-remote-httc2b33e8439af944379acbdd9c3a5fe0bc44bd8a5:go.mod fetc�� om/smartystreets/go-aws-auth origin /bin/git refs/tags/*:refs/usr/sbin/iptables riter/go.mod ps /usr/bin/git (dns block)
  • go.opentelemetry.io
    • Triggering command: /update-job-proxy /update-job-proxy -trimpath= -nolocalimports ux_amd64/vet go_.�� x64/src/net 8925888/b129/ ux_amd64/vet -p weak -lang=go1.24 ux_amd64/vet 8925�� g_.a -I x64/pkg/tool/linux_amd64/vet --gdwarf-5 g/x/sys/cpu -o x64/pkg/tool/linux_amd64/vet (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy -o br-7e8f4456b9ff -j DROP REDACTED 18885ac2:go.mod e/git-remote-https ock fa09c952e3eadbffcat-file /bin/git e/git-remote-httc2b33e8439af944379acbdd9c3a5fe0bc44bd8a5:go.mod fetc�� om/smartystreets/go-aws-auth origin /bin/git refs/tags/*:refs/usr/sbin/iptables riter/go.mod ps /usr/bin/git (dns block)
  • go.uber.org
    • Triggering command: /update-job-proxy /update-job-proxy -trimpath= -nolocalimports ux_amd64/vet go_.�� x64/src/net 8925888/b129/ ux_amd64/vet -p weak -lang=go1.24 ux_amd64/vet 8925�� g_.a -I x64/pkg/tool/linux_amd64/vet --gdwarf-5 g/x/sys/cpu -o x64/pkg/tool/linux_amd64/vet (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy -o br-7e8f4456b9ff -j DROP REDACTED 18885ac2:go.mod e/git-remote-https ock fa09c952e3eadbffcat-file /bin/git e/git-remote-httc2b33e8439af944379acbdd9c3a5fe0bc44bd8a5:go.mod fetc�� om/smartystreets/go-aws-auth origin /bin/git refs/tags/*:refs/usr/sbin/iptables riter/go.mod ps /usr/bin/git (dns block)
  • go4.org
    • Triggering command: /update-job-proxy /update-job-proxy -trimpath= -nolocalimports ux_amd64/vet go_.�� x64/src/net 8925888/b129/ ux_amd64/vet -p weak -lang=go1.24 ux_amd64/vet 8925�� g_.a -I x64/pkg/tool/linux_amd64/vet --gdwarf-5 g/x/sys/cpu -o x64/pkg/tool/linux_amd64/vet (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy -o br-7e8f4456b9ff -j DROP REDACTED 18885ac2:go.mod e/git-remote-https ock fa09c952e3eadbffcat-file /bin/git e/git-remote-httc2b33e8439af944379acbdd9c3a5fe0bc44bd8a5:go.mod fetc�� om/smartystreets/go-aws-auth origin /bin/git refs/tags/*:refs/usr/sbin/iptables riter/go.mod ps /usr/bin/git (dns block)
  • google.golang.org
    • Triggering command: /update-job-proxy /update-job-proxy -trimpath= -nolocalimports ux_amd64/vet go_.�� x64/src/net 8925888/b129/ ux_amd64/vet -p weak -lang=go1.24 ux_amd64/vet 8925�� g_.a -I x64/pkg/tool/linux_amd64/vet --gdwarf-5 g/x/sys/cpu -o x64/pkg/tool/linux_amd64/vet (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy -o br-7e8f4456b9ff -j DROP REDACTED 18885ac2:go.mod e/git-remote-https ock fa09c952e3eadbffcat-file /bin/git e/git-remote-httc2b33e8439af944379acbdd9c3a5fe0bc44bd8a5:go.mod fetc�� om/smartystreets/go-aws-auth origin /bin/git refs/tags/*:refs/usr/sbin/iptables riter/go.mod ps /usr/bin/git (dns block)
  • gopkg.in
    • Triggering command: /update-job-proxy /update-job-proxy -trimpath= -nolocalimports ux_amd64/vet go_.�� x64/src/net 8925888/b129/ ux_amd64/vet -p weak -lang=go1.24 ux_amd64/vet 8925�� g_.a -I x64/pkg/tool/linux_amd64/vet --gdwarf-5 g/x/sys/cpu -o x64/pkg/tool/linux_amd64/vet (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy -o br-7e8f4456b9ff -j DROP REDACTED 18885ac2:go.mod e/git-remote-https ock fa09c952e3eadbffcat-file /bin/git e/git-remote-httc2b33e8439af944379acbdd9c3a5fe0bc44bd8a5:go.mod fetc�� om/smartystreets/go-aws-auth origin /bin/git refs/tags/*:refs/usr/sbin/iptables riter/go.mod ps /usr/bin/git (dns block)
  • gorm.io
    • Triggering command: /update-job-proxy /update-job-proxy -trimpath= -nolocalimports ux_amd64/vet go_.�� x64/src/net 8925888/b129/ ux_amd64/vet -p weak -lang=go1.24 ux_amd64/vet 8925�� g_.a -I x64/pkg/tool/linux_amd64/vet --gdwarf-5 g/x/sys/cpu -o x64/pkg/tool/linux_amd64/vet (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy -o br-7e8f4456b9ff -j DROP REDACTED 18885ac2:go.mod e/git-remote-https ock fa09c952e3eadbffcat-file /bin/git e/git-remote-httc2b33e8439af944379acbdd9c3a5fe0bc44bd8a5:go.mod fetc�� om/smartystreets/go-aws-auth origin /bin/git refs/tags/*:refs/usr/sbin/iptables riter/go.mod ps /usr/bin/git (dns block)
  • gotest.tools
    • Triggering command: /update-job-proxy /update-job-proxy -trimpath= -nolocalimports ux_amd64/vet go_.�� x64/src/net 8925888/b129/ ux_amd64/vet -p weak -lang=go1.24 ux_amd64/vet 8925�� g_.a -I x64/pkg/tool/linux_amd64/vet --gdwarf-5 g/x/sys/cpu -o x64/pkg/tool/linux_amd64/vet (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy -o br-7e8f4456b9ff -j DROP REDACTED 18885ac2:go.mod e/git-remote-https ock fa09c952e3eadbffcat-file /bin/git e/git-remote-httc2b33e8439af944379acbdd9c3a5fe0bc44bd8a5:go.mod fetc�� om/smartystreets/go-aws-auth origin /bin/git refs/tags/*:refs/usr/sbin/iptables riter/go.mod ps /usr/bin/git (dns block)
  • modernc.org
    • Triggering command: /update-job-proxy /update-job-proxy -trimpath= -nolocalimports ux_amd64/vet go_.�� x64/src/net 8925888/b129/ ux_amd64/vet -p weak -lang=go1.24 ux_amd64/vet 8925�� g_.a -I x64/pkg/tool/linux_amd64/vet --gdwarf-5 g/x/sys/cpu -o x64/pkg/tool/linux_amd64/vet (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy -o br-7e8f4456b9ff -j DROP REDACTED 18885ac2:go.mod e/git-remote-https ock fa09c952e3eadbffcat-file /bin/git e/git-remote-httc2b33e8439af944379acbdd9c3a5fe0bc44bd8a5:go.mod fetc�� om/smartystreets/go-aws-auth origin /bin/git refs/tags/*:refs/usr/sbin/iptables riter/go.mod ps /usr/bin/git (dns block)
  • nullprogram.com
    • Triggering command: /update-job-proxy /update-job-proxy -trimpath= -nolocalimports ux_amd64/vet go_.�� x64/src/net 8925888/b129/ ux_amd64/vet -p weak -lang=go1.24 ux_amd64/vet 8925�� g_.a -I x64/pkg/tool/linux_amd64/vet --gdwarf-5 g/x/sys/cpu -o x64/pkg/tool/linux_amd64/vet (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy -o br-7e8f4456b9ff -j DROP REDACTED 18885ac2:go.mod e/git-remote-https ock fa09c952e3eadbffcat-file /bin/git e/git-remote-httc2b33e8439af944379acbdd9c3a5fe0bc44bd8a5:go.mod fetc�� om/smartystreets/go-aws-auth origin /bin/git refs/tags/*:refs/usr/sbin/iptables riter/go.mod ps /usr/bin/git (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[求助]检测是否为GBK,并判断是否要转换</issue_title>
<issue_description>https://github.com/pterodactyl-china/wings/blob/gbkconvert/server/filesystem/compress.go

if ifgbk == true {
utf8Str, _ := simplifiedchinese.GBK.NewDecoder().Bytes([]byte(str))
return string(utf8Str)
} else {
return string(str)
}

判断为true时会将 GBK 转换为 UTF-8,false则直接输出不进行转换。
编译没问题


return string(str)

在237行我想直接输出 179行的str
str := f.Name()

但在测试中,true时转换成功并解压文件,false时直接无响应(卡进程)。

对应的wings测试版本
https://github.com/vlssu/wings/actions/runs/3195622098

如果有更好的思路,可以在源代码的基础上重新编写修复。 https://github.com/pterodactyl-china/wings/blob/develop/server/filesystem/compress.go</issue_description>

<agent_instructions>解压文件可以自动识别是不是GBK还是UTF-8,来正确的解压操作</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@vlssu GBK的压缩包可以用于测试 [测试压缩包.zip](https://github.com/pterodactyl/panel/files/9075730/default.zip) ``` 测试压缩包.zip │ 测试文档.md │ └─测试文件夹 测试核心-arclight-forge-1.18.2-1.0.5.jar ``` UTF-8 的压缩包,可以使用面板上的压缩,再解压来进行测试 @vlssu > 呃 测试用的 UTF8 压缩包结果也被转成 GBK 了,你有什么头绪吗 ![image](https://user-images.githubusercontent.com/17796830/194422198-c7ea6650-ef5e-469c-b652-8c4127ed6359.png) GBK 压缩包测试结果倒是正常的.

用的是这个吗?https://github.com/vlssu/wings/actions/runs/3195622098</comment_new>
<comment_new>@vlssu
在新版中,检测到的文件名是乱码的,并且无法正常工作

ERROR: [Sep  4 17:47:57.524] error while handling HTTP request error=open [�����]��Ȼ����v1.2: invalid argument request_id=16b754ca-9839-4838-8fd6-d0726757b6b4 server_id=e2531742-2c9f-4a52-a1db-95baaa81256f status=500 url=/api/servers/e2531742-2c9f-4a52-a1db-95baaa81256f/files/decompress

Stacktrace:
open [�����]��Ȼ����v1.2: invalid argument
github.com/pterodactyl/wings/router.postServerDecompressFiles
        github.com/pterodactyl/wings/router/router_server_files.go:450
github.com/gin-gonic/gin.(*Context).Next
        github.com/gin-gonic/gin@v1.9.1/context.go:174
github.com/pterodactyl/wings/router/middleware.ServerExists.func1
        github.com/pterodactyl/wings/router/middleware/middleware.go:158
github.com/gin-gonic/gin.(*Context).Next
        github.com/gin-gonic/gin@v1.9.1/context.go:174
github.com/pterodactyl/wings/router/middleware.RequireAuthorization.func1
        github.com/pterodactyl/wings/router/middleware/middleware.go:186
github.com/gin-gonic/gin.(*Context).Next
        github.com/gin-gonic/gin@v1.9.1/context.go:174
github.com/pterodactyl/wings/router/middleware.RequireAuthorization.func1
        github.com/pterodactyl/wings/router/middleware/middleware.go:186
github.com/gin-gonic/gin.(*Context).Next
        github.com/gin-gonic/gin@v1.9.1/context.go:174
github.com/gin-gonic/gin.LoggerWithConfig.func1
        github.com/gin-gonic/gin@v1.9.1/logger.go:240
github.com/gin-gonic/gin.(*Context).Next
        github.com/gin-gonic/gin@v1.9.1/context.go:174
github.com/pterodactyl/wings/router/middleware.AttachApiClient.func1
        github.com/pterodactyl/wings/router/middleware/middleware.go:51
github.com/gin-gonic/gin.(*Context).Next
        github.com/gin-gonic/gin@v1.9.1/context.go:174
github.com/pterodactyl/wings/router/middleware.AttachServerManager.func1
        github.com/pterodactyl/wings/router/middleware/middleware.go:42
github.com/gin-gonic/gin.(*Context).Next
        github.com/gin-gonic/gin@v1.9.1/context.go:174
github.com/pterodactyl/wings/router/middleware.SetAccessControlHeaders.func1
        github.com/pterodactyl/wings/router/middleware/middleware.go:135
github.com/gin-gonic/gin.(*Context).Next
        github.com/gin-gonic/gin@v1.9.1/context.go:174
github.com/pterodactyl/wings/router/middleware.CaptureErrors.func1
        github.com/pterodactyl/wings/router/middleware/middleware.go:68
github.com/gin-gonic/gin.(*Context).Next
        github.com/gin-gonic/gin@v1.9.1/context.go:174
github.com/pterodactyl/wings/router/middleware.AttachRequestID.func1
        github.com/pterodactyl/wings/router/middleware/middleware.go:33
github.com/gin-gonic/gin.(*Context).Next
        github.com/gin-gonic/gin@v1.9.1/context.go:174
github.com/gin-gonic/gin.CustomRecoveryWithWriter.func1
        github.com/gin-gonic/gin@v1.9.1/recovery.go:102
github.com/gin-gonic/gin.(*Context).Next
        github.com/gin-gonic/gin@v1.9.1/context.go:174
github.com/gin-gonic/gin.(*Engine).handleHTTPRequest
        github.com/gin-gonic/gin@v1.9.1/gin.go:620
github.com/gin-gonic/gin.(*Engine).ServeHTTP
        github.com/gin-gonic/gin@v1.9.1/gin.go:576
net/http.serverHandler.ServeHTTP
        net/http/server.go:2947
net/http.(*conn).serve
        n...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes pterodactyl-china/wings#4

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

Co-authored-by: vlssu <43847794+vlssu@users.noreply.github.com>
@vlssu vlssu marked this pull request as ready for review January 19, 2026 15:58
Co-authored-by: vlssu <43847794+vlssu@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix GBK detection and conversion issue Auto-detect and convert GBK-encoded archive filenames to UTF-8 Jan 19, 2026
Copilot AI requested a review from vlssu January 19, 2026 16:01
@vlssu vlssu merged commit 0b30e08 into develop Jan 19, 2026
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.

2 participants