-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
zip archive invalid but works with other utilities #45338
Comments
I downloaded your zip file and ran this program. It worked for me, in that Show us your Go code. package main
import (
"archive/zip"
"fmt"
"os"
)
func main() {
_, err := zip.OpenReader(os.Args[1])
if err != nil {
fmt.Println(err)
}
} |
Note that "client" here is from google/go-github and u, resp, err := client.Actions.DownloadArtifact(ctx, a.org, a.repo, a.ID, false)
if err != nil {
type ghErr struct {
Message string `json:"message"`
}
e := &ghErr{}
json.NewDecoder(io.LimitReader(resp.Body, 32*1024)).Decode(e)
return errors.Wrapf(err, "error getting url to download artifact: %s", e.Message)
}
resp.Body.Close()
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil)
if err != nil {
return err
}
if err := os.MkdirAll(dir, 0700); err != nil {
return errors.Wrap(err, "error creating artifact dir")
}
f, err := os.OpenFile(filepath.Join(dir, a.Name)+".zip", os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0600)
if err != nil {
return errors.Wrap(err, "error creating save file")
}
defer f.Close()
resp, err = client.Do(ctx, req, f)
if err != nil {
return err
}
defer resp.Body.Close()
if _, err := f.Seek(0, io.SeekStart); err != nil {
return errors.Wrap(err, "error seeking back to save file start")
}
r, err := zip.NewReader(f, a.Size)
if err != nil {
return errors.Wrapf(err, "error making zip reader from file %s", f.Name())
}
if err := unzipGo(r, a, dir); err != nil {
return err
} Working on a utility to download github actions artifacts... I'll post full code to a repo soon just need to clean up some hardcoded things first. |
What is |
Oh... that's it! Github is reporting the wrong size for the file. |
❤️ Sorry for the noise. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I have this zip archive (linked to the source here, but also attached to the issue below) which archive/zip says is invalid.
This is created by github actions artifact uploader.
TestResults MacOS.zip
What did you expect to see?
Maybe at least details on what makes it invalid but genereally I'd expect a way to make it work since other zip utilities seem to be OK with it.
What did you see instead?
zip.NewReader
gives me:The text was updated successfully, but these errors were encountered: