Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

archive/zip: unzip with java fails on tip #25215

Closed
gwik opened this issue May 2, 2018 · 3 comments
Closed

archive/zip: unzip with java fails on tip #25215

gwik opened this issue May 2, 2018 · 3 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@gwik
Copy link
Contributor

gwik commented May 2, 2018

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

go version devel +b1d1ec9183 Mon Apr 30 21:26:00 2018 +0000 linux/amd64

Does this issue reproduce with the latest release?

No. On tip.

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/antoninamand/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/antoninamand/go"
GORACE=""
GOROOT="/home/antoninamand/gotip"
GOTMPDIR=""
GOTOOLDIR="/home/antoninamand/gotip/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
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-build168212714=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Unzip a zip file generated with go tip containing an empty directory. Unzipping raises an exception (java.util.zip.ZipException).

Create a zip with go:

package main

import (
	"archive/zip"
	"os"
)

func main() {
	f, err := os.OpenFile(os.Args[1], os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
	if err != nil {
		panic(err)
	}
	z := zip.NewWriter(f)
	_, err = z.Create("dir/")
	if err != nil {
		panic(err)
	}
	if err := z.Close(); err != nil {
		panic(err)
	}
	if err := f.Close(); err != nil {
		panic(err)
	}
}

Unzip with java:

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class Main {
    public static void main(String[] args) {
        try {
            FileInputStream fi = new FileInputStream(args[0]);
            ZipInputStream z = new ZipInputStream(fi);

            while (true) {
                ZipEntry entry = z.getNextEntry();
                if (entry == null) return;
                System.out.println(entry.getName());
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(2);
        }

    }
}

Output:

go version
go version devel +b1d1ec9183 Mon Apr 30 21:26:00 2018 +0000 linux/amd64
go run zipfilewithdir.go file.zip
javac Main.java
java Main file.zip
dir/
java.util.zip.ZipException: invalid stored block lengths
	at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
	at java.util.zip.ZipInputStream.read(ZipInputStream.java:194)
	at java.util.zip.ZipInputStream.closeEntry(ZipInputStream.java:140)
	at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:118)
	at Main.main(Main.java:13)
Makefile:2: recipe for target 'run' failed
make: *** [run] Error 2

Note that the "dir/" entry is listed but it fails after that.

It doesn't fail when the archive is generated with go 1.10.1.
The compatibility was broken by 8cd00a5.

What did you expect to see?

It should unzip without error.

What did you see instead?

It raises a java exception.

@agnivade agnivade added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 2, 2018
@agnivade agnivade added this to the Go1.11 milestone May 2, 2018
@agnivade
Copy link
Contributor

agnivade commented May 2, 2018

/cc @dsnet

@gwik
Copy link
Contributor Author

gwik commented May 2, 2018

Java version:

openjdk version "1.8.0_162"
OpenJDK Runtime Environment (build 1.8.0_162-8u162-b12-0ubuntu0.17.10.2-b12)
OpenJDK 64-Bit Server VM (build 25.162-b12, mixed mode)

@gopherbot
Copy link

Change https://golang.org/cl/110795 mentions this issue: archive/zip: restore compat with java zip reader

@bradfitz bradfitz added NeedsFix The path to resolution is known, but the work has not been done. release-blocker labels May 2, 2018
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 2, 2018
@golang golang locked and limited conversation to collaborators May 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

4 participants