mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
Fix failure of tarfile extract when dest_path has symlinks
This commit is contained in:
@@ -171,10 +171,13 @@ func ExtractAllFromTar(tr *tar.Reader, dest_path string, optss ...TarExtractOpti
|
|||||||
if len(optss) > 0 {
|
if len(optss) > 0 {
|
||||||
opts = optss[0]
|
opts = optss[0]
|
||||||
}
|
}
|
||||||
dest_path, err = filepath.Abs(dest_path)
|
if dest_path, err = filepath.Abs(dest_path); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if dest_path, err = filepath.EvalSymlinks(dest_path); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dest_path = filepath.Clean(dest_path)
|
||||||
|
|
||||||
mode := func(hdr int64) fs.FileMode {
|
mode := func(hdr int64) fs.FileMode {
|
||||||
return fs.FileMode(hdr) & (fs.ModePerm | fs.ModeSetgid | fs.ModeSetuid | fs.ModeSticky)
|
return fs.FileMode(hdr) & (fs.ModePerm | fs.ModeSetgid | fs.ModeSetuid | fs.ModeSticky)
|
||||||
@@ -190,6 +193,7 @@ func ExtractAllFromTar(tr *tar.Reader, dest_path string, optss ...TarExtractOpti
|
|||||||
count++
|
count++
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
needed_prefix := dest_path + string(os.PathSeparator)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
var hdr *tar.Header
|
var hdr *tar.Header
|
||||||
@@ -208,7 +212,7 @@ func ExtractAllFromTar(tr *tar.Reader, dest_path string, optss ...TarExtractOpti
|
|||||||
if dest, err = EvalSymlinksThatExist(dest); err != nil {
|
if dest, err = EvalSymlinksThatExist(dest); err != nil {
|
||||||
return count, err
|
return count, err
|
||||||
}
|
}
|
||||||
if !strings.HasPrefix(filepath.Clean(dest), filepath.Clean(dest_path)+string(os.PathSeparator)) {
|
if !strings.HasPrefix(dest, needed_prefix) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
switch hdr.Typeflag {
|
switch hdr.Typeflag {
|
||||||
|
|||||||
Reference in New Issue
Block a user