Skip to content

archive/zip: allows writing data for a directory #24043

Description

@dsnet

Consider the following:

bb := new(bytes.Buffer)
zw := zip.NewWriter(bb)
w, _ := zw.Create("blah/")
if _, err := w.Write([]byte("Hello, world!")); err == nil {
    fmt.Println("unexpected Write success")
}
zw.Close()

A trailing forward-slash indicates intent to encode a directory. The API for Create and CreateHeader returns an io.Writer, which allows a user to write "data" for a directory, which has no sensible meaning. It turns out that the Writer does actually encode the data into the archive, but the various zip readers I tested just ignore the data.

I believe the io.Writer returned by Create and CreateHeader should just return an error.

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

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions