Skip to content

Fix GBK filename decoding and file handle leaks in archive decompression#27

Merged
vlssu merged 5 commits intodevelopfrom
copilot/fix-http-request-error
Feb 12, 2026
Merged

Fix GBK filename decoding and file handle leaks in archive decompression#27
vlssu merged 5 commits intodevelopfrom
copilot/fix-http-request-error

Conversation

Copy link

Copilot AI commented Feb 12, 2026

Decompressing ZIP archives with GBK-encoded filenames (common in Chinese Windows systems) fails with invalid argument errors. Large file extraction occasionally fails with unexpected EOF due to file handle conflicts.

Changes

  • New ZipFS wrapper (server/filesystem/archiverext/zip.go): Implements fs.FS with automatic GBK→UTF-8 filename transcoding. Detects non-UTF-8 filenames and decodes them as GBK transparently during filesystem operations.

  • File handle cleanup: Added io.Closer implementation to ZipFS and proper defer close() in SpaceAvailableForDecompression() to prevent handle leaks between space check and extraction phases.

  • Test coverage: Added test case validating SpaceAvailableForDecompression() with GBK-encoded filenames.

Implementation

The ZipFS wrapper intercepts all filename operations and applies this heuristic:

func decodeZipFilename(filename string) string {
    if utf8.ValidString(filename) {
        return filename
    }
    decoded, err := simplifiedchinese.GBK.NewDecoder().String(filename)
    if err != nil {
        return filename
    }
    return decoded
}

This handles the vast majority of Chinese ZIP archives while remaining transparent to UTF-8 archives.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits February 12, 2026 13:50
- Create ZipFS wrapper in archiverext package to handle GBK-encoded filenames
- Automatically decode GBK to UTF-8 when walking ZIP archives
- Update archiverFileSystem to use ZipFS wrapper for ZIP files
- Add test for SpaceAvailableForDecompression with GBK filenames

Co-authored-by: vlssu <43847794+vlssu@users.noreply.github.com>
- Add Close() method to ZipFS to properly close underlying file
- Update SpaceAvailableForDecompression to close filesystem after use
- Prevents file handle leaks that could cause "unexpected EOF" errors

Co-authored-by: vlssu <43847794+vlssu@users.noreply.github.com>
Co-authored-by: vlssu <43847794+vlssu@users.noreply.github.com>
- Fix directory detection logic to properly handle trailing slashes
- Replace deprecated interface{} with any
- Improve directory classification using FileInfo().IsDir()

Co-authored-by: vlssu <43847794+vlssu@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix invalid argument error for HTTP request handling Fix GBK filename decoding and file handle leaks in archive decompression Feb 12, 2026
@vlssu vlssu marked this pull request as ready for review February 12, 2026 14:00
@vlssu vlssu merged commit 82cb955 into develop Feb 12, 2026
6 checks passed
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