From da8c06e03e0960d012c15dc4a4c7efbb4f451034 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 11 Jun 2014 13:46:41 +0200 Subject: [PATCH] Fixed handling of broken archives --- .../acp/form/PackageStartInstallForm.class.php | 14 +++++++++++++- .../validation/PackageValidationArchive.class.php | 9 +++++++++ .../validation/PackageValidationManager.class.php | 15 +++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php b/wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php index 5529fd025d..801704fd99 100755 --- a/wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PackageStartInstallForm.class.php @@ -14,6 +14,7 @@ use wcf\system\WCF; use wcf\system\WCFACP; use wcf\util\FileUtil; use wcf\util\StringUtil; +use wcf\system\package\validation\PackageValidationException; /** * Shows the package install and update form. @@ -137,7 +138,18 @@ class PackageStartInstallForm extends AbstractForm { throw new UserInputException('uploadPackage', 'uploadFailed'); } - PackageValidationManager::getInstance()->validate($this->uploadPackage['name'], false); + if (!PackageValidationManager::getInstance()->validate($this->uploadPackage['name'], false)) { + $exception = PackageValidationManager::getInstance()->getException(); + if ($exception instanceof PackageValidationException) { + switch ($exception->getCode()) { + case PackageValidationException::INVALID_PACKAGE_NAME: + case PackageValidationException::MISSING_PACKAGE_XML: + throw new UserInputException('uploadPackage', 'noValidPackage'); + break; + } + } + } + $this->package = PackageValidationManager::getInstance()->getPackageValidationArchive()->getPackage(); } diff --git a/wcfsetup/install/files/lib/system/package/validation/PackageValidationArchive.class.php b/wcfsetup/install/files/lib/system/package/validation/PackageValidationArchive.class.php index db3e71f4a7..2928a76d55 100644 --- a/wcfsetup/install/files/lib/system/package/validation/PackageValidationArchive.class.php +++ b/wcfsetup/install/files/lib/system/package/validation/PackageValidationArchive.class.php @@ -222,6 +222,15 @@ class PackageValidationArchive implements \RecursiveIterator { } } + /** + * Returns the occured exception. + * + * @return \Exception + */ + public function getException() { + return $this->exception; + } + /** * Returns the exception message. * diff --git a/wcfsetup/install/files/lib/system/package/validation/PackageValidationManager.class.php b/wcfsetup/install/files/lib/system/package/validation/PackageValidationManager.class.php index 1e68507e9a..28fb3e56a4 100644 --- a/wcfsetup/install/files/lib/system/package/validation/PackageValidationManager.class.php +++ b/wcfsetup/install/files/lib/system/package/validation/PackageValidationManager.class.php @@ -132,6 +132,21 @@ class PackageValidationManager extends SingletonFactory { return ''; } + /** + * Recursively traverses the package validation archives and returns the first exception. + * + * @return \Exception + */ + public function getException() { + foreach ($this->getPackageValidationArchiveList() as $packageArchive) { + if ($packageArchive->getException() !== null) { + return $packageArchive->getException(); + } + } + + return null; + } + /** * Validates an instruction against the corresponding package installation plugin. * -- 2.20.1