Skip to content

Commit

Permalink
Fix off-by-one error in zip extraction
Browse files Browse the repository at this point in the history
Fixes #18
  • Loading branch information
zyedidia committed Jan 5, 2022
1 parent 3e664b5 commit 5f2a54b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,18 @@ func NewZipArchive(data []byte, d DecompFn) (Archive, error) {
zr, err := zip.NewReader(r, int64(len(data)))
return &ZipArchive{
r: zr,
idx: 0,
idx: -1,
}, err
}

func (z *ZipArchive) Next() (File, error) {
z.idx++

if z.idx < 0 || z.idx >= len(z.r.File) {
return File{}, io.EOF
}

f := z.r.File[z.idx]
z.idx++

return File{
Name: f.Name,
Expand All @@ -88,6 +89,9 @@ func (z *ZipArchive) Next() (File, error) {
}

func (z *ZipArchive) ReadAll() ([]byte, error) {
if z.idx < 0 || z.idx >= len(z.r.File) {
return nil, io.EOF
}
f := z.r.File[z.idx]
rc, err := f.Open()
if err != nil {
Expand Down

0 comments on commit 5f2a54b

Please sign in to comment.