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: checksum error #11145

Closed
dvyukov opened this issue Jun 10, 2015 · 1 comment
Closed

archive/zip: checksum error #11145

dvyukov opened this issue Jun 10, 2015 · 1 comment
Assignees

Comments

@dvyukov
Copy link
Member

@dvyukov dvyukov commented Jun 10, 2015

The following program crashes with the panic:

package main

import (
    "archive/zip"
    "bytes"
    "io/ioutil"
)

func main() {
    headers := []zip.FileHeader{
        {Name:"0", Method:8},
        {Name:"1", Method:8},
    }
    contents := [][]byte{
        []byte("a"),
        []byte("b"),
    }
    buf := new(bytes.Buffer)
    w := zip.NewWriter(buf)
    for i, h := range headers {
        w1, err := w.CreateHeader(&h)
        if err != nil {
            panic(err)
        }
        _, err = w1.Write(contents[i])
        if err != nil {
            panic(err)
        }
    }
    err := w.Close()
    if err != nil {
        panic(err)
    }

    z1, err := zip.NewReader(bytes.NewReader(buf.Bytes()), int64(len(buf.Bytes())))
    if err != nil {
        panic(err)
    }
    var headers1 []zip.FileHeader
    var contents1 [][]byte
    for _, f := range z1.File {
        r, err := f.Open()
        if err != nil {
            panic(err)
        }
        c, err := ioutil.ReadAll(r)
        if err != nil {
            panic(err)
        }
        headers1 = append(headers1, f.FileHeader)
        contents1 = append(contents1, c)
        r.Close()
    }
}
panic: zip: checksum error

goroutine 1 [running]:
main.main()
    zip.go:48 +0x8f8

go version devel +b0532a9 Mon Jun 8 05:13:15 2015 +0000 linux/amd64

@dvyukov
Copy link
Member Author

@dvyukov dvyukov commented Jun 10, 2015

I think this is dup of #11144 (FileHeader is shared between files).

@adg adg closed this Jun 10, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.