<commit_before><?php
namespace wcf\system\upload;
use wcf\util\ImageUtil;

/**
 * Upload file validation strategy implementation for trophy images.
 *
 * @author	<NAME>
 * @copyright	2001-2018 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\System\Upload
 * @since	3.1
 */
class TrophyImageUploadFileValidationStrategy implements IUploadFileValidationStrategy {
	/**
	 * minimum trophy image width and height
	 * @var integer
	 */
	const MIN_TROPHY_IMAGE_SIZE = 64;
	
	/**
	 * @inheritDoc
	 */
	public function validate(UploadFile $uploadFile) {
		if ($uploadFile->getErrorCode()) {
			$uploadFile->setValidationErrorType('uploadFailed');
			return false;
		}
		
		if ($uploadFile->getImageData() === null) {
			$uploadFile->setValidationErrorType('noImage');
			return false;
		}
		
		if ($uploadFile->getImageData()['width'] != $uploadFile->getImageData()['height']) {
			$uploadFile->setValidationErrorType('notSquared');
			return false;
		}
		
		if ($uploadFile->getImageData()['width'] < self::MIN_TROPHY_IMAGE_SIZE) {
			$uploadFile->setValidationErrorType('tooSmall');
			return false; 
		}
		
		if (!ImageUtil::checkImageContent($uploadFile->getLocation())) {
			$uploadFile->setValidationErrorType('noImage');
			return false; 
		}
		
		return true;
	}
}<commit_msg>Validate uploaded trophy images whether their are an image<commit_after><?php
namespace wcf\system\upload;
use wcf\util\ImageUtil;

/**
 * Upload file validation strategy implementation for trophy images.
 *
 * @author	<NAME>
 * @copyright	2001-2018 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\System\Upload
 * @since	3.1
 */
class TrophyImageUploadFileValidationStrategy implements IUploadFileValidationStrategy {
	/**
	 * minimum trophy image width and height
	 * @var integer
	 */
	const MIN_TROPHY_IMAGE_SIZE = 64;
	
	/**
	 * @inheritDoc
	 */
	public function validate(UploadFile $uploadFile) {
		if ($uploadFile->getErrorCode()) {
			$uploadFile->setValidationErrorType('uploadFailed');
			return false;
		}
		
		if ($uploadFile->getImageData() === null) {
			$uploadFile->setValidationErrorType('noImage');
			return false;
		}
		
		if ($uploadFile->getImageData()['width'] != $uploadFile->getImageData()['height']) {
			$uploadFile->setValidationErrorType('notSquared');
			return false;
		}
		
		if ($uploadFile->getImageData()['width'] < self::MIN_TROPHY_IMAGE_SIZE) {
			$uploadFile->setValidationErrorType('tooSmall');
			return false; 
		}
		
		if (!ImageUtil::checkImageContent($uploadFile->getLocation())) {
			$uploadFile->setValidationErrorType('noImage');
			return false; 
		}
		
		if (!ImageUtil::isImage($uploadFile->getLocation(), $uploadFile->getFilename())) {
			$uploadFile->setValidationErrorType('noImage');
			return false; 
		}
		
		return true;
	}
}
{'fraction_non_alphanumeric': 0.13979591836734695, 'fraction_numerical': 0.00816326530612245, 'mean_word_length': 4.677606177606178, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '987619', 'n_tokens_mistral': 1027, 'n_tokens_neox': 874, 'n_words': 174}