Skip to content

archive/zip: fails to encode filenames with utf-8 chars if 'Modified' is not set #44187

Description

@Bysmyyr

What version of Go are you using (go version)?

➜ go version
go version go1.15.6 linux/amd64


Does this issue reproduce with the latest release?

that's almost latests

What operating system and processor architecture are you using (go env)?

go env Output
➜ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/olli/.cache/go-build"
GOENV="/home/olli/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/olli/go/pkg/mod"
GONOPROXY="github.com/SharperShape"
GOOS="linux"
GOPATH="/home/olli/go"
GOPROXY="direct"
GOROOT="/usr/lib/golang"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/olli/code/ziponator/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build503259521=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Creating a zipfile with nonASCII characters in zipped files fail to encode if Modified is not set. The behavior could be ok still but currently, it anyway checks that if utf-8 mode is needed which makes the programmer to think it should work without any tricks.

so:

w := zip.NewWriter(os.Stdout)
f, err := w.Create("asdää123ääääääend")
… write to f …

…doesn't work, but:

w := zip.NewWriter(os.Stdout)
fh := zip.FileHeader{
	Name:   "asdää123ääääääend",
	Method: zip.Deflate,
	Modified: time.Now(),
}
f, err := w.CreateHeader(&fh)

works

Problem confirmed here:
https://gophers.slack.com/archives/C029RQSEE/p1612881140479100?thread_ts=1612878897.474000&cid=C029RQSEE

What did you expect to see?

asdää123ääääääend

What did you see instead?

asd├д├д123├д├д├д├д├д├дend

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions