Skip to content

archive/zip: file might overflowed while decompressing #49791

Description

@mengzhuo

Consider this logic from tip.

n, err = r.rc.Read(b)
r.hash.Write(b[:n])
r.nread += uint64(n)
if err == nil {
return
}

The reader only checks file size after all the read of compress file is done, however it's possible that a malformed zip file already overflow during the decompress process.

PoC ( you can setup a malformed zip file for sure) :

func TestUnderSize(t *testing.T) {
	z, err := OpenReader("testdata/readme.zip")
	if err != nil {
		t.Fatal(err)
	}
	defer z.Close()

	for _, f := range z.File {
		f.UncompressedSize64 = 1
	}

	for _, f := range z.File {
		rd, err := f.Open()
		if err != nil {
			t.Fatal(err)
		}
		defer rd.Close()

		_, err = io.Copy(io.Discard, rd)
		if err == nil || err != nil && err != ErrFileSize {
			t.Fatal(err)
		}
	}
}

We need an easy fail-fast while reading the zip file.

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