statIndex example


    public function getContents($name)
    {
        return $this->stream->getFromName($name);
    }

    /** * @param int $position */
    public function getEntry($position)
    {
        return $this->stream->statIndex($position);
    }

    /** * @return bool */
    public function close()
    {
        return $this->stream->close();
    }

    /** * Give a meaningful error message to the user. * * @param int $retval * @param string $file * * @return string */

    public function getContents($name)
    {
        return $this->stream->getFromName($name);
    }

    /** * @param int $position */
    public function getEntry($position)
    {
        return $this->stream->statIndex($position);
    }

    /** * @return bool */
    public function close()
    {
        return $this->stream->close();
    }

    /** * Give a meaningful error message to the user. * * @param int $retval * @param string $file * * @return string */
$prefix = $this->getLegacyPluginPrefix($archive);

        $this->assertValid($archive$prefix);
    }

    /** * @param string $prefix */
    private function assertValid(ZipArchive $archive$prefix)
    {
        for ($i = 2; $i < $archive->numFiles; ++$i) {
            $stat = $archive->statIndex($i);

            $this->assertNoDirectoryTraversal($stat['name']);
            $this->assertPrefix($stat['name']$prefix);
        }
    }

    /** * @return string */
    private function getLegacyPluginPrefix(ZipArchive $archive)
    {
        
$this->isPlugin($archive) => PluginManagementService::PLUGIN,
                $this->isApp($archive) => PluginManagementService::APP,
                default => throw PluginException::noPluginFoundInZip($zipFilePath)
            };
        } finally {
            $archive->close();
        }
    }

    public function isPlugin(\ZipArchive $archive): bool
    {
        $entry = $archive->statIndex(0);
        if ($entry === false) {
            return false;
        }

        $pluginName = explode('/', (string) $entry['name'])[0];
        $composerFile = $pluginName . '/composer.json';
        $manifestFile = $pluginName . '/manifest.xml';

        $statComposerFile = $archive->statName($composerFile);
        $statManifestFile = $archive->statName($manifestFile);

        
namespace Shopware\Bundle\PluginInstallerBundle\Service;

use ZipArchive;

class PluginZipDetector
{
    /** * @return bool */
    public function isLegacyPlugin(ZipArchive $archive)
    {
        $entry = $archive->statIndex(0);
        $rootDirectory = explode('/', $entry['name'])[0];

        return \in_array($rootDirectory['Frontend', 'Backend', 'Core']);
    }

    /** * @return bool */
    public function isPlugin(ZipArchive $archive)
    {
        $entry = $archive->statIndex(0);

        
$archive->close();
    }

    /** * Iterates all files of the provided zip archive * path and validates the plugin namespace, directory traversal * and multiple plugin directories. */
    private function validatePluginZip(string $prefix, \ZipArchive $archive): void
    {
        for ($i = 2; $i < $archive->numFiles; ++$i) {
            $stat = $archive->statIndex($i);
            \assert($stat !== false);

            $this->assertNoDirectoryTraversal($stat['name']);
            $this->assertPrefix($stat['name']$prefix);
        }
    }

    private function getPluginName(\ZipArchive $archive): string
    {
        $entry = $archive->statIndex(0);
        \assert($entry !== false);

        
$this->clearOpcodeCache();
    }

    /** * Iterates all files of the provided zip archive * path and validates the plugin namespace, directory traversal * and multiple plugin directories. */
    private function validatePluginZip(string $prefix, ZipArchive $archive): void
    {
        for ($i = 2; $i < $archive->numFiles; ++$i) {
            $stat = $archive->statIndex($i);
            if (!\is_array($stat)) {
                continue;
            }

            $this->assertNoDirectoryTraversal($stat['name']);
            $this->assertPrefix($stat['name']$prefix);
        }
    }

    private function getPluginPrefix(ZipArchive $archive): string
    {
        
$z = new ZipArchive();

    $zopen = $z->open( $file, ZIPARCHIVE::CHECKCONS );

    if ( true !== $zopen ) {
        return new WP_Error( 'incompatible_archive', __( 'Incompatible Archive.' ), array( 'ziparchive_error' => $zopen ) );
    }

    $uncompressed_size = 0;

    for ( $i = 0; $i < $z->numFiles; $i++ ) {
        $info = $z->statIndex( $i );

        if ( ! $info ) {
            return new WP_Error( 'stat_failed_ziparchive', __( 'Could not retrieve file from archive.' ) );
        }

        if ( str_starts_with( $info['name'], '__MACOSX/' ) ) { // Skip the OS X-created __MACOSX directory.             continue;
        }

        // Don't extract invalid files:         if ( 0 !== validate_file( $info['name'] ) ) {
            
Home | Imprint | This part of the site doesn't use cookies.