Validates the owner element

@return   bool    whether uploaded file's MIME type is correct
490358
protected function validateOwner()
    {
        $value = $this->owner->getValue();
        if (!isset($value['error']) || UPLOAD_ERR_NO_FILE == $value['error']) {
            return true;
        }
        $mime = $this->getConfig();
        return is_array($mime)? in_array($value['type'], $mime):
                                $value['type'] == $mime;
    }
494507
public function isValid()
    {
        foreach ($this->objects as $fileInfo) {
            // Before validation callback
            $this->applyCallback('beforeValidation', $fileInfo);

            // Check is uploaded file
            if ($fileInfo->isUploadedFile() === false) {
                $this->errors[] = sprintf(
                    '%s: %s',
                    $fileInfo->getNameWithExtension(),
                    'Is not an uploaded file'
                );
                continue;
            }

            // Apply user validations
            foreach ($this->validations as $validation) {
                try {
                    $validation->validate($fileInfo);
                } catch (\Upload\Exception $e) {
                    $this->errors[] = sprintf(
                        '%s: %s',
                        $fileInfo->getNameWithExtension(),
                        $e->getMessage()
                    );
                }
            }

            // After validation callback
            $this->applyCallback('afterValidation', $fileInfo);
        }

        return empty($this->errors);
    }
1146076
public function canUpload()
    {
        $access = eZUser::instance()->hasAccessTo( 'content', 'create' );
        if ( $access['accessWord'] === 'no' )
        {
            return false;
        }
        $ini = eZINI::instance( 'upload.ini' );
        $uploadableClassList = $ini->variable( 'CreateSettings', 'MimeClassMap' );
        $uploadableClassList[] = $ini->variable( 'CreateSettings', 'DefaultClass' );
        $classContent = $this->attribute->attribute( 'class_content' );

        $intersect = array_intersect( $classContent['class_constraint_list'], $uploadableClassList );
        if ( !empty( $classContent['class_constraint_list'] ) && empty( $intersect ) )
        {
            return false;
        }
        return true;
    }
722258
public function isValid()
	{
		// loop through all files
		foreach ($this->container as $file)
		{
			// return false at the first non-valid file
			if ( ! $file->isValid())
			{
				return false;
			}
		}

		// only return true if there are uploaded files, and they are all valid
		return empty($this->container) ? false : true;
	}
1330101
public function is_valid_image() {
        $mimetype = $this->get_mimetype();
        if (!file_mimetype_in_typegroup($mimetype, 'web_image')) {
            return false;
        }
        if (!$info = $this->get_imageinfo()) {
            return false;
        }
        if ($info['mimetype'] !== $mimetype) {
            return false;
        }
        // ok, GD likes this image
        return true;
    }
508825
protected function validateDestinationCreate()
    {
        if ($this->isError()) {
            return null;
        }

        $name = $this->getSubmitted('name');
        $files = $this->getSubmitted('files');

        /* @var $file \SplFileInfo */
        $file = reset($files);
        $directory = $file->getRealPath();

        if (file_exists("$directory/$name")) {
            $this->setError('name', $this->translation->text('Destination already exists'));
            return false;
        }

        $this->setSubmitted('destination', "$directory/$name");
        return true;
    }
156370
public function validateRequest(): bool
    {
        if ($this->useNativeSession) {
            if (!isset($_SESSION[$this->sessionIndex])) {
                return false;
            }
            /** @var array<string, array<string, mixed>> $sess */
            $sess =& $_SESSION[$this->sessionIndex];
        } else {
            if (!isset($this->session[$this->sessionIndex])) {
                return false;
            }
            /** @var array<string, array<string, mixed>> $sess */
            $sess =& $this->session[$this->sessionIndex];
        }

        if (
            empty($this->post[$this->formIndex]) ||
            empty($this->post[$this->formToken])
        ) {
            // User must transmit a complete index/token pair
            return false;
        }

        // Let's pull the POST data
        /** @var string $index */
        $index = $this->post[$this->formIndex];
        /** @var string $token */
        $token = $this->post[$this->formToken];
        if (!\is_string($index) || !\is_string($token)) {
            return false;
        }

        if (!isset($sess[$index])) {
            // CSRF Token not found
            return false;
        }

        if (!\is_string($index) || !\is_string($token)) {
            return false;
        }

        // Grab the value stored at $index
        /** @var array<string, mixed> $stored */
        $stored = $sess[$index];

        // We don't need this anymore
        if ($this->deleteToken($sess[$index])) {
            unset($sess[$index]);
        }

        // Which form action="" is this token locked to?
        /** @var string $lockTo */
        $lockTo = $this->server[$this->lock_type];
        if (\preg_match('#/$#', $lockTo)) {
            // Trailing slashes are to be ignored
            $lockTo = Binary::safeSubstr(
                $lockTo,
                0,
                Binary::safeStrlen($lockTo) - 1
            );
        }

        if (!\hash_equals($lockTo, (string) $stored['lockTo'])) {
            // Form target did not match the request this token is locked to!
            return false;
        }

        // This is the expected token value
        if ($this->hmac_ip === false) {
            // We just stored it wholesale
            /** @var string $expected */
            $expected = $stored['token'];
        } else {
            // We mixed in the client IP address to generate the output
            /** @var string $expected */
            $expected = Base64UrlSafe::encode(
                \hash_hmac(
                    $this->hashAlgo,
                    isset($this->server['REMOTE_ADDR'])
                        ? (string) $this->server['REMOTE_ADDR']
                        : '127.0.0.1',
                    (string) Base64UrlSafe::decode((string) $stored['token']),
                    true
                )
            );
        }
        return \hash_equals($token, $expected);
    }
798291
protected function validateFileManager()
    {
        $selected = $this->isQuery('selected');
        $files = $selected ? $this->data_selected : array($this->data_file);

        $this->setSubmitted('filemanager');
        $this->setSubmitted('files', $files);
        $this->setSubmitted('command', $this->data_command);

        $this->validateComponent("file_manager_{$this->data_command['command_id']}");
        return !$this->hasErrors(false);
    }
753592
public function validateChunk()
    {
        $file = $this->request->getFile();

        if (!$file) {
            return false;
        }

        if (!isset($file['tmp_name']) || !isset($file['size']) || !isset($file['error'])) {
            return false;
        }

        if ($this->request->getCurrentChunkSize() != $file['size']) {
            return false;
        }

        if ($file['error'] !== UPLOAD_ERR_OK) {
            return false;
        }

        return true;
    }
723511
def validate_file_ownership(config):
    """"""
    files = config.get('files', {})
    for file_name, options in files.items():
        for key in options.keys():
            if key not in ["owner", "group", "mode"]:
                raise RuntimeError(
                    "Invalid ownership configuration: {}".format(key))
        owner = options.get('owner', config.get('owner', 'root'))
        group = options.get('group', config.get('group', 'root'))
        optional = options.get('optional', config.get('optional', 'False'))
        if '*' in file_name:
            for file in glob.glob(file_name):
                if file not in files.keys():
                    if os.path.isfile(file):
                        _validate_file_ownership(owner, group, file, optional)
        else:
            if os.path.isfile(file_name):
                _validate_file_ownership(owner, group, file_name, optional)
896214
protected function isValidFormat()
    {
        //    Reading 2048 bytes should be enough to validate that the format is HTML
        $data = fread($this->fileHandle, 2048);
        if ((strpos($data, '<') !== false) &&
                (strlen($data) !== strlen(strip_tags($data)))) {
            return true;
        }

        return false;
    }
165501
private function check_if_allowed()
    {
        $check = \wp_check_filetype_and_ext($this->data['tmp_name'], $this->client_name);

        if ($check['type'] !== false) {
            $this->guessed_type = $check['type'];
            $this->guessed_extension = $check['ext'];
        }

        if (($check['type'] === false || $check['ext'] === false)
            && !\current_user_can('unfiltered_upload')
        ) {
            return false;
        }

        $allowed_types = \get_allowed_mime_types();

        return \in_array($this->client_type, $allowed_types);
    }
1353218
public function validate()
	{
		$sourceFiles = $this->getFileList($this->sourcePath);
		// License file is required but missing from en/, so we add it here
		$sourceFiles[] = $this->sourceLanguagePath . 'LICENSE';
		$sourceFiles = array_unique($sourceFiles);

		// Get $lang['direction'] of translation to allow additional rtl-files for rtl-translations
		$filePath = $this->originPath . '/' . $this->originLanguagePath . 'common.php';

		if ($this->safeMode)
		{
			$lang = ValidatorRunner::langParser($filePath);
		}

		else
		{
			include($filePath);
		}

		$direction = $lang['DIRECTION'];
		// Throw error, if invalid direction is used
		if (!in_array($direction, array('rtl', 'ltr')))
		{
			$this->output->addMessage(Output::FATAL, 'DIRECTION needs to be rtl or ltr');
		}

		$originFiles = $this->getFileList($this->originPath);

		$missingSubsilver2Files = $availableSubsilver2Files = array();
		$validFiles = array();
		foreach ($sourceFiles as $sourceFile)
		{
			$testOriginFile = str_replace('/' . $this->sourceIso . '/', '/' . $this->originIso . '/', $sourceFile);
			if (!in_array($testOriginFile, $originFiles))
			{
				$this->output->addMessage(Output::FATAL, 'Missing required file', $testOriginFile);
			}
			else if (substr($sourceFile, -4) != '.gif' && substr($sourceFile, -12) != 'imageset.cfg')
			{
				$validFiles[$sourceFile] = $testOriginFile;
			}
		}

		foreach ($originFiles as $origin_file)
		{
			$testSourceFile = str_replace('/' . $this->originIso . '/', '/' . $this->sourceIso . '/', $origin_file);
			if (!in_array($testSourceFile, $sourceFiles))
			{
				if (in_array($origin_file, array(
					$this->originLanguagePath . 'AUTHORS.md',
					$this->originLanguagePath . 'CHANGELOG.md',
					$this->originLanguagePath . 'README.md',
					$this->originLanguagePath . 'VERSION.md',
				)))
				{
					$this->output->addMessage(Output::NOTICE, 'Found additional file', $origin_file);
				}
				else
				{
					if (substr($origin_file, -10) === '/index.htm' || $origin_file === 'index.htm')
					{
						$level = Output::NOTICE;
					}
					else if ($this->phpbbVersion === '3.2' && strpos($origin_file, 'styles/subsilver2/') === 0)
					{
						$level = Output::FATAL;
					}
					else if (in_array(substr($origin_file, -4), array('.gif', '.png')) && $direction === 'rtl')
					{
						$level = Output::WARNING;
					}
					else if (substr($origin_file, -3) !==	'.md')
					{
						$level = Output::FATAL;
					}
					else
					{
						$level = Output::ERROR;
					}

					$this->output->addMessage($level, 'Found additional file', $origin_file);
				}

				if (substr($origin_file, -14) === '/site_logo.gif')
				{
					$this->output->addMessage(Output::FATAL, 'Found additional file', $origin_file);
				}
			}
		}

		return $validFiles;
	}
1180997
public function mime()
    {
        if (!$this->exists()) {
            return false;
        }
        if (class_exists('finfo')) {
            $finfo = new finfo(FILEINFO_MIME);
            $type = $finfo->file($this->pwd());
            if (!$type) {
                return false;
            }
            list($type) = explode(';', $type);

            return $type;
        }
        if (function_exists('mime_content_type')) {
            return mime_content_type($this->pwd());
        }

        return false;
    }
1374888
public function isValid()
    {
        /**
         * First, check if the upload is valid or not
         */
        if (!parent::isValid()) {
            return false;
        }

        $value = $this->field->getValue();

        // if here, we know that the field is uploaded.

        // check if it's an image, and get it's size
        $size = @getimagesize($value['tmp_name']);
        if ($size === false) {
            $this->setErrorMessage($this->messages['not_an_image']);
            return false;
        }
        list ($width, $height) = $size;

        /**
         * Validate the aspect ratio.
         */
        if (!$this->validateAspectRatio($width, $height)) {
            return false;
        }


        /**
         * Validate the proportions
         */
        if (!$this->validateSize($width, $height)) {
            return false;
        }

        // if here, everything is ok!
        return true;
    }
1334607
protected function _validateUpload() : bool
    {
        if (! $this->request->getData('file')) {
            $this->flash->error('Please choose a file to upload.');

            return false;
        }

        if (! in_array($this->request->getData('file.type'), $this->__supportedMimeTypes)) {
            $this->flash->error('Unable to upload file, unsupported file provided.');

            return false;
        }

        return true;
    }
1289978
public function validate()
    {
        if (($_FILES) && (isset($_FILES[$this->name]['name']))) {
            $value = $_FILES[$this->name]['name'];
            $size  = $_FILES[$this->name]['size'];
        } else {
            $value = null;
            $size  = null;
        }
        // Check if the element is required
        if (($this->required) && empty($value)) {
            $this->errors[] = 'This field is required.';
        }
        // Check field validators
        if (count($this->validators) > 0) {
            foreach ($this->validators as $validator) {
                if ($validator instanceof \Pop\Validator\ValidatorInterface) {
                    $class =  get_class($validator);
                    if ((null !== $size) &&
                        (('Pop\Validator\LessThanEqual' == $class) || ('Pop\Validator\GreaterThanEqual' == $class) ||
                         ('Pop\Validator\LessThan' == $class) || ('Pop\Validator\GreaterThan' == $class))) {
                        if (!$validator->evaluate($size)) {
                            $this->errors[] = $validator->getMessage();
                        }
                    } else {
                        if (!$validator->evaluate($value)) {
                            $this->errors[] = $validator->getMessage();
                        }
                    }
                } else if (is_callable($validator)) {
                    $result = call_user_func_array($validator, [$value]);
                    if (null !== $result) {
                        $this->errors[] = $result;
                    }
                }
            }
        }
        return (count($this->errors) == 0);
    }