diff --git a/Archive/Tar.php b/Archive/Tar.php index 8a2d2db..ccbae6d 100644 --- a/Archive/Tar.php +++ b/Archive/Tar.php @@ -2124,7 +2124,25 @@ public function _extractList( } } } elseif ($v_header['typeflag'] == "2") { - if (strpos(realpath(dirname($v_header['link'])), realpath($p_path)) !== 0) { + $link_depth = 0; + foreach (explode("/", $v_header['filename']) as $dir) { + if ($dir === "..") { + $link_depth--; + } elseif ($dir !== "" && $dir !== "." ) { + $link_depth++; + } + } + foreach (explode("/", $v_header['link']) as $dir){ + if ($link_depth <= 0) { + break; + } + if ($dir === "..") { + $link_depth--; + } elseif ($dir !== "" && $dir !== ".") { + $link_depth++; + } + } + if (str_starts_with($v_header['link'], "/") or $link_depth <= 0) { $this->_error( 'Out-of-path file extraction {' . $v_header['filename'] . ' --> ' .