Repository navigation
Conversation
The invalid UTF-8 bytes of an entry name were deleted, and the cleaned
name was then used to know if the entry is a directory. A file named
"photos/\xe1" (ß in CP437, as written by archivers that do not set the
UTF-8 flag) became "photos/", so it was skipped as a directory and its
content silently dropped. Distinct names could also collide ("\x82.txt"
and "\x8a.txt" both became ".txt"). The directory check now reads the
original header, and names that are not valid UTF-8 are decoded from
CP437, the usual DOS code page (#5131).
archive/zip reports a CRC or data descriptor mismatch on the last read,
after every byte has been written, so file.Close() committed a file with
unverified content before the job failed. The file is now destroyed when
the copy fails (#5134).
Fixes #5131
Fixes #5134
shepilov
force-pushed
the
fix/unzip-entry-names-and-checksum
branch
from
November 3, 2026 15:13
39ffb37 to
1b3acf2
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5131
Fixes #5134
Problem
utils.CleanUTF8), then used that cleaned name to decide whether the entry is a directory.photos/\xe1(ßin CP437, as written by archivers that do not set the UTF-8 flag, common on Windows) becamephotos/, so it was skipped as a directory and its content silently dropped while the job reported success. Distinct names could also collide (\x82.txtand\x8a.txtboth became.txt), which failed the whole job.archive/zipreports a CRC or data descriptor mismatch on the lastRead, after every byte has been written.file.Close()then committed a file with unverified content, and the job failed half-way.Solution
f.Mode().IsDir()before touching the name), andf.Nameis no longer mutated.golang.org/x/textis already a direct dependency. CP437 is a heuristic: names written in another code page (Latin-1, CP866, Shift-JIS...) are readable only partly, but they are no longer lost.io.Copyfails afterClose()committed the file, the file is destroyed (fs.DestroyFile) and the error is returned.Test plan
unzip keeps the files with a non UTF-8 name:photos/\xe1,\x82.txtand\x8a.txtare extracted asphotos/ß,é.txtandè.txtwith their content, andcafé.txt(valid UTF-8, no UTF-8 flag) stayscafé.txtunzip does not keep an entry with a bad checksum: the job fails withzip.ErrChecksumanda.txtdoes not existgo test ./worker/archive/passes, including the existing path traversal tests