Skip to content

Commit 82d7592

Browse files
ForestEckhardtryanmoran
authored andcommitted
Fixes vacation regression
- Some archive files can have a relative reference to the destination directory i.e. ./ . These files should still be able to be decompressed so logic has been added to see if the destination path of the file is the destination directory itself.
1 parent 258636b commit 82d7592

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

vacation/vacation.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,10 @@ func (z ZipArchive) Decompress(destination string) error {
409409
}
410410

411411
// This function checks to see that the given path is within the destination
412-
// directory
412+
// directory or it is the destination directory itself i.e. ./
413413
func checkExtractPath(filePath string, destination string) error {
414414
destpath := filepath.Join(destination, filePath)
415-
if !strings.HasPrefix(destpath, filepath.Clean(destination)+string(os.PathSeparator)) {
415+
if !strings.HasPrefix(destpath, filepath.Clean(destination)+string(os.PathSeparator)) && destpath != filepath.Clean(destination) {
416416
return fmt.Errorf("illegal file path %q: the file path does not occur within the destination directory", filePath)
417417
}
418418
return nil

vacation/vacation_tar_gzip_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ func testVacationTarGzip(t *testing.T, context spec.G, it spec.S) {
3535
gw := gzip.NewWriter(buffer)
3636
tw := tar.NewWriter(gw)
3737

38+
// Some archive files will make a relative top level path directory these
39+
// should still successfully decompress.
40+
Expect(tw.WriteHeader(&tar.Header{Name: "./", Mode: 0755, Typeflag: tar.TypeDir})).To(Succeed())
41+
_, err = tw.Write(nil)
42+
Expect(err).NotTo(HaveOccurred())
43+
3844
Expect(tw.WriteHeader(&tar.Header{Name: "some-dir", Mode: 0755, Typeflag: tar.TypeDir})).To(Succeed())
3945
_, err = tw.Write(nil)
4046
Expect(err).NotTo(HaveOccurred())

vacation/vacation_zip_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ func testVacationZip(t *testing.T, context spec.G, it spec.S) {
4242
_, err = symlink.Write([]byte(filepath.Join("some-dir", "some-other-dir", "some-file")))
4343
Expect(err).NotTo(HaveOccurred())
4444

45+
// Some archive files will make a relative top level path directory these
46+
// should still successfully decompress.
47+
_, err = zw.Create("./")
48+
Expect(err).NotTo(HaveOccurred())
49+
4550
_, err = zw.Create("some-dir/")
4651
Expect(err).NotTo(HaveOccurred())
4752

0 commit comments

Comments
 (0)