if err != nil {
return err
}
- prefix := mod.Path + "@" + mod.Version
+ prefix := mod.Path + "@" + mod.Version + "/"
for _, f := range z.File {
if !strings.HasPrefix(f.Name, prefix) {
z.Close()
- return fmt.Errorf("zip for %s has unexpected file %s", prefix, f.Name)
+ return fmt.Errorf("zip for %s has unexpected file %s", prefix[:len(prefix)-1], f.Name)
}
}
z.Close()
// module root.
continue
}
+ base.Errorf("%s", p.Error)
}
todo = append(todo, p)
}
+ base.ExitIfErrors()
// If -d was specified, we're done after the download: no build.
// (The load.PackagesAndErrors is what did the download
if strings.HasPrefix(f.Name, ".") {
continue
}
- zf, err := z.Create(path + "@" + vers + "/" + f.Name)
+ var zipName string
+ if strings.HasPrefix(f.Name, "/") {
+ zipName = f.Name[1:]
+ } else {
+ zipName = path + "@" + vers + "/" + f.Name
+ }
+ zf, err := z.Create(zipName)
if err != nil {
return cached{nil, err}
}
--- /dev/null
+rsc.io/badzip v1.0.0
+written by hand
+
+-- .mod --
+module rsc.io/badzip
+-- .info --
+{"Version":"v1.0.0"}
+-- x.go --
+package x
+-- /rsc.io/badzip@v1.0.0.txt --
+This file should not be here.
--- /dev/null
+# Zip files with unexpected file names inside should be rejected.
+env GO111MODULE=on
+
+! go get -d rsc.io/badzip
+stderr 'zip for rsc.io/badzip@v1.0.0 has unexpected file rsc.io/badzip@v1.0.0.txt'
+
+! go build rsc.io/badzip
+stderr 'zip for rsc.io/badzip@v1.0.0 has unexpected file rsc.io/badzip@v1.0.0.txt'
+
+-- go.mod --
+module m