Skip to content

Commit

Permalink
test(pkgdata): handle empty names in MakeDeb (#85)
Browse files Browse the repository at this point in the history
MakeDeb() now expects that all provided tar entries have a non-empty
name. Otherwise it panics on array out of bounds access. Fix it.

We can create tarballs containing entries with empty name just fine. It
makes GNU tar fail when extracting, but it fails gracefully with

  tar: Substituting `.' for empty member name
  -rw-r--r-- root/root         0 1970-01-01 01:00
  tar: .: Cannot open: File exists
  tar: Exiting with failure status due to previous errors
  • Loading branch information
woky authored Aug 28, 2023
1 parent 0f94f2c commit a6e7c43
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/testutil/pkgdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"archive/tar"
"bytes"
"encoding/base64"
"strings"
"time"

"github.com/blakesmith/ar"
Expand Down Expand Up @@ -174,7 +175,7 @@ func fixupTarEntry(entry *TarEntry) {
if hdr.Typeflag == 0 {
if hdr.Linkname != "" {
hdr.Typeflag = tar.TypeSymlink
} else if hdr.Name[len(hdr.Name)-1] == '/' {
} else if strings.HasSuffix(hdr.Name, "/") {
hdr.Typeflag = tar.TypeDir
} else {
hdr.Typeflag = tar.TypeReg
Expand Down
15 changes: 15 additions & 0 deletions internal/testutil/pkgdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,21 @@ var pkgdataCheckEntries = []checkTarEntry{{
ModTime: epochStartTime,
Format: tar.FormatGNU,
},
}, {
testutil.TarEntry{
Header: tar.Header{
Name: "",
},
},
tar.Header{
Typeflag: tar.TypeReg,
Name: "",
Mode: 00644,
Uname: "root",
Gname: "root",
ModTime: epochStartTime,
Format: tar.FormatGNU,
},
}}

func (s *pkgdataSuite) TestMakeDeb(c *C) {
Expand Down

0 comments on commit a6e7c43

Please sign in to comment.