Projet

Général

Profil

Révision 27e02aed

Ajouté par Assos Assos il y a plus de 4 ans

-a

Voir les différences:

drupal7/modules/system/system.tar.inc
40 40
 */
41 41

  
42 42
 /**
43
 * Note on Drupal 8 porting.
44
 * This file origin is Tar.php, release 1.4.5 (stable) with some code
45
 * from PEAR.php, release 1.10.5 (stable) both at http://pear.php.net.
43
 * Note on Drupal 7 porting.
44
 * This file origin is Tar.php, release 1.4.9 (stable) with some code
45
 * from PEAR.php, release 1.10.10 (stable) both at http://pear.php.net.
46 46
 * To simplify future porting from pear of this file, you should not
47 47
 * do cosmetic or other non significant changes to this file.
48 48
 * The following changes have been done:
49
 *  Added namespace Drupal\Core\Archiver.
50 49
 *  Removed require_once 'PEAR.php'.
51 50
 *  Added defintion of OS_WINDOWS taken from PEAR.php.
52
 *  Renamed class to ArchiveTar.
53 51
 *  Removed extends PEAR from class.
54 52
 *  Removed call parent:: __construct().
55 53
 *  Changed PEAR::loadExtension($extname) to this->loadExtension($extname).
56 54
 *  Added function loadExtension() taken from PEAR.php.
57 55
 *  Changed all calls of unlink() to drupal_unlink().
58 56
 *  Changed $this->error_object = &$this->raiseError($p_message)
59
 *  to throw new \Exception($p_message).
57
 *  to throw new Exception($p_message).
60 58
 */
61 59

  
62
 /**
63
 * Note on Drupal 7 backporting from Drupal 8.
64
 * File origin is core/lib/Drupal/Core/Archiver/ArchiveTar.php from Drupal 8.
65
 * The following changes have been done:
66
 *  Removed namespace Drupal\Core\Archiver.
67
 *  Renamed class to Archive_Tar.
68
 *  Changed \Exception to Exception.
69
 */
70

  
71

  
72 60
// Drupal removal require_once 'PEAR.php'.
73 61

  
74 62
// Drupal addition OS_WINDOWS as defined in PEAR.php.
......
153 141
     */
154 142
    public $error_object = null;
155 143

  
144
    /**
145
     * Format for data extraction
146
     *
147
     * @var string
148
     */
149
    public $_fmt = '';
150

  
151
    /**
152
     * @var int Length of the read buffer in bytes
153
     */
154
    protected $buffer_length;
155

  
156 156
    /**
157 157
     * Archive_Tar Class constructor. This flavour of the constructor only
158 158
     * declare a new Archive_Tar object, identifying it by the name of the
......
165 165
     *               parameter indicates if gzip, bz2 or lzma2 compression
166 166
     *               is required.  For compatibility reason the
167 167
     *               boolean value 'true' means 'gz'.
168
     * @param int $buffer_length Length of the read buffer in bytes
168 169
     *
169 170
     * @return bool
170 171
     */
171
    public function __construct($p_tarname, $p_compress = null)
172
    public function __construct($p_tarname, $p_compress = null, $buffer_length = 512)
172 173
    {
173 174
        // Drupal removal parent::__construct().
174 175

  
......
263 264

  
264 265
        if (version_compare(PHP_VERSION, "5.5.0-dev") < 0) {
265 266
            $this->_fmt = "a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/" .
266
                   "a8checksum/a1typeflag/a100link/a6magic/a2version/" .
267
                   "a32uname/a32gname/a8devmajor/a8devminor/a131prefix";
267
                "a8checksum/a1typeflag/a100link/a6magic/a2version/" .
268
                "a32uname/a32gname/a8devmajor/a8devminor/a131prefix";
268 269
        } else {
269 270
            $this->_fmt = "Z100filename/Z8mode/Z8uid/Z8gid/Z12size/Z12mtime/" .
270
                   "Z8checksum/Z1typeflag/Z100link/Z6magic/Z2version/" .
271
                   "Z32uname/Z32gname/Z8devmajor/Z8devminor/Z131prefix";
271
                "Z8checksum/Z1typeflag/Z100link/Z6magic/Z2version/" .
272
                "Z32uname/Z32gname/Z8devmajor/Z8devminor/Z131prefix";
272 273
        }
273 274

  
274 275

  
276
        $this->buffer_length = $buffer_length;
275 277
    }
276 278

  
277 279
    public function __destruct()
......
371 373
    /**
372 374
     * @param string $p_path
373 375
     * @param bool $p_preserve
376
     * @param bool $p_symlinks
374 377
     * @return bool
375 378
     */
376
    public function extract($p_path = '', $p_preserve = false)
379
    public function extract($p_path = '', $p_preserve = false, $p_symlinks = true)
377 380
    {
378
        return $this->extractModify($p_path, '', $p_preserve);
381
        return $this->extractModify($p_path, '', $p_preserve, $p_symlinks);
379 382
    }
380 383

  
381 384
    /**
......
616 619
     *                               removed if present at the beginning of
617 620
     *                               the file/dir path.
618 621
     * @param boolean $p_preserve Preserve user/group ownership of files
622
     * @param boolean $p_symlinks Allow symlinks.
619 623
     *
620 624
     * @return boolean true on success, false on error.
621 625
     * @see    extractList()
622 626
     */
623
    public function extractModify($p_path, $p_remove_path, $p_preserve = false)
627
    public function extractModify($p_path, $p_remove_path, $p_preserve = false, $p_symlinks = true)
624 628
    {
625 629
        $v_result = true;
626 630
        $v_list_detail = array();
......
632 636
                "complete",
633 637
                0,
634 638
                $p_remove_path,
635
                $p_preserve
639
                $p_preserve,
640
                $p_symlinks
636 641
            );
637 642
            $this->_close();
638 643
        }
......
676 681
     *                               removed if present at the beginning of
677 682
     *                               the file/dir path.
678 683
     * @param boolean $p_preserve Preserve user/group ownership of files
684
     * @param boolean $p_symlinks Allow symlinks.
679 685
     *
680 686
     * @return true on success, false on error.
681 687
     * @see    extractModify()
682 688
     */
683
    public function extractList($p_filelist, $p_path = '', $p_remove_path = '', $p_preserve = false)
689
    public function extractList($p_filelist, $p_path = '', $p_remove_path = '', $p_preserve = false, $p_symlinks = true)
684 690
    {
685 691
        $v_result = true;
686 692
        $v_list_detail = array();
......
701 707
                "partial",
702 708
                $v_list,
703 709
                $p_remove_path,
704
                $p_preserve
710
                $p_preserve,
711
                $p_symlinks
705 712
            );
706 713
            $this->_close();
707 714
        }
......
1326 1333
                return false;
1327 1334
            }
1328 1335

  
1329
            while (($v_buffer = fread($v_file, 512)) != '') {
1330
                $v_binary_data = pack("a512", "$v_buffer");
1336
            while (($v_buffer = fread($v_file, $this->buffer_length)) != '') {
1337
                $buffer_length = strlen("$v_buffer");
1338
                if ($buffer_length != $this->buffer_length) {
1339
                    $pack_size = ((int)($buffer_length / 512) + 1) * 512;
1340
                    $pack_format = sprintf('a%d', $pack_size);
1341
                } else {
1342
                    $pack_format = sprintf('a%d', $this->buffer_length);
1343
                }
1344
                $v_binary_data = pack($pack_format, "$v_buffer");
1331 1345
                $this->_writeBlock($v_binary_data);
1332 1346
            }
1333 1347

  
......
1532 1546
        $p_type = '',
1533 1547
        $p_uid = 0,
1534 1548
        $p_gid = 0
1535
    ) {
1549
    )
1550
    {
1536 1551
        $p_filename = $this->_pathReduction($p_filename);
1537 1552

  
1538 1553
        if (strlen($p_filename) > 99) {
......
1745 1760
        }
1746 1761

  
1747 1762
        // ----- Extract the checksum
1748
        $v_header['checksum'] = OctDec(trim($v_data['checksum']));
1763
        $v_data_checksum = trim($v_data['checksum']);
1764
        if (!preg_match('/^[0-7]*$/', $v_data_checksum)) {
1765
            $this->_error(
1766
                'Invalid checksum for file "' . $v_data['filename']
1767
                . '" : ' . $v_data_checksum . ' extracted'
1768
            );
1769
            return false;
1770
        }
1771

  
1772
        $v_header['checksum'] = OctDec($v_data_checksum);
1749 1773
        if ($v_header['checksum'] != $v_checksum) {
1750 1774
            $v_header['filename'] = '';
1751 1775

  
......
1839 1863
        if (strpos($file, 'phar://') === 0) {
1840 1864
            return true;
1841 1865
        }
1842
        if (strpos($file, DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR) !== false) {
1843
            return true;
1844
        }
1845
        if (strpos($file, '..' . DIRECTORY_SEPARATOR) === 0) {
1866
        if (strpos($file, '../') !== false || strpos($file, '..\\') !== false) {
1846 1867
            return true;
1847 1868
        }
1848 1869
        return false;
......
1908 1929
            }
1909 1930

  
1910 1931
            switch ($v_header['typeflag']) {
1911
                case 'L': {
1912
                    if (!$this->_readLongHeader($v_header)) {
1913
                        return null;
1932
                case 'L':
1933
                    {
1934
                        if (!$this->_readLongHeader($v_header)) {
1935
                            return null;
1936
                        }
1914 1937
                    }
1915
                } break;
1938
                    break;
1916 1939

  
1917
                case 'K': {
1918
                    $v_link_header = $v_header;
1919
                    if (!$this->_readLongHeader($v_link_header)) {
1920
                        return null;
1940
                case 'K':
1941
                    {
1942
                        $v_link_header = $v_header;
1943
                        if (!$this->_readLongHeader($v_link_header)) {
1944
                            return null;
1945
                        }
1946
                        $v_header['link'] = $v_link_header['filename'];
1921 1947
                    }
1922
                    $v_header['link'] = $v_link_header['filename'];
1923
                } break;
1948
                    break;
1924 1949
            }
1925 1950

  
1926 1951
            if ($v_header['filename'] == $p_filename) {
......
1960 1985
     * @param string $p_file_list
1961 1986
     * @param string $p_remove_path
1962 1987
     * @param bool $p_preserve
1988
     * @param bool $p_symlinks
1963 1989
     * @return bool
1964 1990
     */
1965 1991
    public function _extractList(
......
1968 1994
        $p_mode,
1969 1995
        $p_file_list,
1970 1996
        $p_remove_path,
1971
        $p_preserve = false
1972
    ) {
1997
        $p_preserve = false,
1998
        $p_symlinks = true
1999
    )
2000
    {
1973 2001
        $v_result = true;
1974 2002
        $v_nb = 0;
1975 2003
        $v_extract_all = true;
......
2022 2050
            }
2023 2051

  
2024 2052
            switch ($v_header['typeflag']) {
2025
                case 'L': {
2026
                    if (!$this->_readLongHeader($v_header)) {
2027
                        return null;
2053
                case 'L':
2054
                    {
2055
                        if (!$this->_readLongHeader($v_header)) {
2056
                            return null;
2057
                        }
2028 2058
                    }
2029
                } break;
2059
                    break;
2030 2060

  
2031
                case 'K': {
2032
                    $v_link_header = $v_header;
2033
                    if (!$this->_readLongHeader($v_link_header)) {
2034
                        return null;
2061
                case 'K':
2062
                    {
2063
                        $v_link_header = $v_header;
2064
                        if (!$this->_readLongHeader($v_link_header)) {
2065
                            return null;
2066
                        }
2067
                        $v_header['link'] = $v_link_header['filename'];
2035 2068
                    }
2036
                    $v_header['link'] = $v_link_header['filename'];
2037
                } break;
2069
                    break;
2038 2070
            }
2039 2071

  
2040 2072
            // ignore extended / pax headers
......
2146 2178
                            }
2147 2179
                        }
2148 2180
                    } elseif ($v_header['typeflag'] == "2") {
2181
                        if (!$p_symlinks) {
2182
                            $this->_warning('Symbolic links are not allowed. '
2183
                                . 'Unable to extract {'
2184
                                . $v_header['filename'] . '}'
2185
                            );
2186
                            return false;
2187
                        }
2149 2188
                        if (@file_exists($v_header['filename'])) {
2150 2189
                            @drupal_unlink($v_header['filename']);
2151 2190
                        }

Formats disponibles : Unified diff