diff --git a/.gitattributes b/.gitattributes index f8b91505bc98..0fec00026fd8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -26,3 +26,6 @@ # The OSS fuzz files are bunary /ext/date/tests/ossfuzz*.txt binary + +# The phar has some binary +/pear/install-pear-nozlib.phar binary diff --git a/.gitignore b/.gitignore index 49acc9f2e178..0e3edde1be99 100644 --- a/.gitignore +++ b/.gitignore @@ -125,7 +125,6 @@ config.h.in # ------------------------------------------------------------------------------ /ext/phar/phar.phar /ext/phar/phar.php -/pear/install-pear-nozlib.phar /sapi/cgi/php-cgi /sapi/fpm/php-fpm /sapi/phpdbg/phpdbg diff --git a/pear/Makefile.frag b/pear/Makefile.frag index 9408757a3ad7..366ad4a9575c 100644 --- a/pear/Makefile.frag +++ b/pear/Makefile.frag @@ -3,11 +3,8 @@ peardir=$(PEAR_INSTALLDIR) # Skip all php.ini files altogether PEAR_INSTALL_FLAGS = -n -dshort_open_tag=0 -dopen_basedir= -derror_reporting=1803 -dmemory_limit=-1 -ddetect_unicode=0 -WGET = `which wget 2>/dev/null` -FETCH = `which fetch 2>/dev/null` PEAR_PREFIX = -dp a${program_prefix} PEAR_SUFFIX = -ds a$(program_suffix) -PEAR_INSTALLER_URL = https://pear.php.net/install-pear-nozlib.phar install-pear-installer: $(SAPI_CLI_PATH) @$(top_builddir)/sapi/cli/php $(PEAR_INSTALL_FLAGS) pear/install-pear-nozlib.phar -d "$(peardir)" -b "$(bindir)" ${PEAR_PREFIX} ${PEAR_SUFFIX} @@ -15,17 +12,7 @@ install-pear-installer: $(SAPI_CLI_PATH) install-pear: @echo "Installing PEAR environment: $(INSTALL_ROOT)$(peardir)/" @if test ! -f $(builddir)/install-pear-nozlib.phar; then \ - if test -f $(srcdir)/install-pear-nozlib.phar; then \ - cp $(srcdir)/install-pear-nozlib.phar $(builddir)/install-pear-nozlib.phar; \ - else \ - if test ! -z "$(WGET)" && test -x "$(WGET)"; then \ - "$(WGET)" "${PEAR_INSTALLER_URL}" -nd -P $(builddir)/; \ - elif test ! -z "$(FETCH)" && test -x "$(FETCH)"; then \ - "$(FETCH)" -o $(builddir)/ "${PEAR_INSTALLER_URL}"; \ - else \ - $(top_builddir)/sapi/cli/php -n $(srcdir)/fetch.php "${PEAR_INSTALLER_URL}" $(builddir)/install-pear-nozlib.phar; \ - fi \ - fi \ + cp $(srcdir)/install-pear-nozlib.phar $(builddir)/install-pear-nozlib.phar; \ fi @if test -f $(builddir)/install-pear-nozlib.phar && $(mkinstalldirs) $(INSTALL_ROOT)$(peardir); then \ $(MAKE) -s install-pear-installer; \ diff --git a/pear/fetch.php b/pear/fetch.php deleted file mode 100644 index 56767b62cb70..000000000000 --- a/pear/fetch.php +++ /dev/null @@ -1,74 +0,0 @@ - \n", $argv[0]); - exit(1); -} - -function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) { - static $filesize = null; - - switch($notification_code) { - case STREAM_NOTIFY_RESOLVE: - case STREAM_NOTIFY_AUTH_REQUIRED: - case STREAM_NOTIFY_COMPLETED: - case STREAM_NOTIFY_FAILURE: - case STREAM_NOTIFY_AUTH_RESULT: - /* Ignore */ - break; - - case STREAM_NOTIFY_REDIRECTED: - echo "Being redirected to: ", $message, "\n"; - break; - - case STREAM_NOTIFY_CONNECT: - echo "Connected...\n"; - break; - - case STREAM_NOTIFY_FILE_SIZE_IS: - $filesize = $bytes_max; - echo "Filesize: ", $filesize, "\n"; - break; - - case STREAM_NOTIFY_MIME_TYPE_IS: - echo "Mime-type: ", $message, "\n"; - break; - - case STREAM_NOTIFY_PROGRESS: - if ($bytes_transferred > 0) { - if (!isset($filesize)) { - printf("\rUnknown filesize.. %2d kb done..", $bytes_transferred/1024); - } else { - $length = (int)(($bytes_transferred/$filesize)*100); - printf("\r[%-100s] %d%% (%2d/%2d kb)", str_repeat("=", $length). ">", $length, ($bytes_transferred/1024), $filesize/1024); - } - } - break; - } -} - -isset($argv[1], $argv[2]) or usage($argv); - -if (!isset($_ENV['http_proxy'])) { - $copt = null; -} else { - $copt = array( - 'http' => array( - 'proxy' => preg_replace('/^http/i', 'tcp', $_ENV['http_proxy']), - 'request_fulluri' => true, - ), - ); -} - -$ctx = stream_context_create($copt, array("notification" => "stream_notification_callback")); - -$fp = fopen($argv[1], "r", false, $ctx); -if (is_resource($fp) && file_put_contents($argv[2], $fp)) { - echo "\nDone!\n"; - exit(0); -} - -$err = error_get_last(); -echo "\nError..\n", $err["message"], "\n"; -exit(1); diff --git a/pear/install-pear-nozlib.phar b/pear/install-pear-nozlib.phar new file mode 100644 index 000000000000..fde49385da04 --- /dev/null +++ b/pear/install-pear-nozlib.phar @@ -0,0 +1,99871 @@ + + * @author Greg Beaver + * @link http://www.synapticmedia.net Synaptic Media + * @version Id$ + * @package PHP_Archive + * @category PHP + */ + +class PHP_Archive +{ + const GZ = 0x00001000; + const BZ2 = 0x00002000; + const SIG = 0x00010000; + const SHA1 = 0x0002; + const MD5 = 0x0001; + const SHA256 = 0x0003; + const SHA512 = 0x0004; + const OPENSSL = 0x0010; + /** + * Whether this archive is compressed with zlib + * + * @var bool + */ + private $_compressed; + /** + * @var string Real path to the .phar archive + */ + private $_archiveName = null; + /** + * Current file name in the phar + * @var string + */ + protected $currentFilename = null; + /** + * Length of current file in the phar + * @var string + */ + protected $internalFileLength = null; + /** + * true if the current file is an empty directory + * @var string + */ + protected $isDir = false; + /** + * Current file statistics (size, creation date, etc.) + * @var string + */ + protected $currentStat = null; + /** + * @var resource|null Pointer to open .phar + */ + protected $fp = null; + /** + * @var int Current Position of the pointer + */ + protected $position = 0; + + /** + * Map actual realpath of phars to meta-data about the phar + * + * Data is indexed by the alias that is used by internal files. In other + * words, if a file is included via: + * + * require_once 'phar://PEAR.phar/PEAR/Installer.php'; + * + * then the alias is "PEAR.phar" + * + * Information stored is a boolean indicating whether this .phar is compressed + * with zlib, another for bzip2, phar-specific meta-data, and + * the precise offset of internal files + * within the .phar, used with the {@link $_manifest} to load actual file contents + * @var array + */ + private static $_pharMapping = array(); + /** + * Map real file paths to alias used + * + * @var array + */ + private static $_pharFiles = array(); + /** + * File listing for the .phar + * + * The manifest is indexed per phar. + * + * Files within the .phar are indexed by their relative path within the + * .phar. Each file has this information in its internal array + * + * - 0 = uncompressed file size + * - 1 = timestamp of when file was added to phar + * - 2 = offset of file within phar relative to internal file's start + * - 3 = compressed file size (actual size in the phar) + * @var array + */ + private static $_manifest = array(); + /** + * Absolute offset of internal files within the .phar, indexed by absolute + * path to the .phar + * + * @var array + */ + private static $_fileStart = array(); + /** + * file name of the phar + * + * @var string + */ + private $_basename; + + + /** + * Default MIME types used for the web front controller + * + * @var array + */ + public static $defaultmimes = array( + 'aif' => 'audio/x-aiff', + 'aiff' => 'audio/x-aiff', + 'arc' => 'application/octet-stream', + 'arj' => 'application/octet-stream', + 'art' => 'image/x-jg', + 'asf' => 'video/x-ms-asf', + 'asx' => 'video/x-ms-asf', + 'avi' => 'video/avi', + 'bin' => 'application/octet-stream', + 'bm' => 'image/bmp', + 'bmp' => 'image/bmp', + 'bz2' => 'application/x-bzip2', + 'css' => 'text/css', + 'doc' => 'application/msword', + 'dot' => 'application/msword', + 'dv' => 'video/x-dv', + 'dvi' => 'application/x-dvi', + 'eps' => 'application/postscript', + 'exe' => 'application/octet-stream', + 'gif' => 'image/gif', + 'gz' => 'application/x-gzip', + 'gzip' => 'application/x-gzip', + 'htm' => 'text/html', + 'html' => 'text/html', + 'ico' => 'image/x-icon', + 'jpe' => 'image/jpeg', + 'jpg' => 'image/jpeg', + 'jpeg' => 'image/jpeg', + 'js' => 'application/x-javascript', + 'log' => 'text/plain', + 'mid' => 'audio/x-midi', + 'mov' => 'video/quicktime', + 'mp2' => 'audio/mpeg', + 'mp3' => 'audio/mpeg3', + 'mpg' => 'audio/mpeg', + 'pdf' => 'aplication/pdf', + 'png' => 'image/png', + 'rtf' => 'application/rtf', + 'tif' => 'image/tiff', + 'tiff' => 'image/tiff', + 'txt' => 'text/plain', + 'xml' => 'text/xml', + ); + + public static $defaultphp = array( + 'php' => true + ); + + public static $defaultphps = array( + 'phps' => true + ); + + public static $deny = array('/.+\.inc$/'); + + public static function viewSource($archive, $file) + { + // security, idea borrowed from PHK + if (!file_exists($archive . '.introspect')) { + header("HTTP/1.0 404 Not Found"); + return false; + } + if (self::_fileExists($archive, $_GET['viewsource'])) { + $source = highlight_file('phar://install-pear-nozlib.phar/' . + $_GET['viewsource'], true); + header('Content-Type: text/html'); + header('Content-Length: ' . strlen($source)); + echo 'Source of ', + htmlspecialchars($_GET['viewsource']), ''; + echo '

Source of ', + htmlspecialchars($_GET['viewsource']), '

'; + if (isset($_GET['introspect'])) { + echo 'Return to ', htmlspecialchars($_GET['introspect']), '
'; + } + echo $source; + return false; + } else { + header("HTTP/1.0 404 Not Found"); + return false; + } + + } + + public static function introspect($archive, $dir) + { + // security, idea borrowed from PHK + if (!file_exists($archive . '.introspect')) { + header("HTTP/1.0 404 Not Found"); + return false; + } + if (!$dir) { + $dir = '/'; + } + $dir = self::processFile($dir); + if ($dir[0] != '/') { + $dir = '/' . $dir; + } + try { + $self = htmlspecialchars($_SERVER['PHP_SELF']); + $iterate = new DirectoryIterator('phar://install-pear-nozlib.phar' . $dir); + echo 'Introspect ', htmlspecialchars($dir), + '

Introspect ', htmlspecialchars($dir), + '