Index: wp-admin/includes/class-wp-upgrader.php
===================================================================
--- wp-admin/includes/class-wp-upgrader.php	(revision 18557)
+++ wp-admin/includes/class-wp-upgrader.php	(working copy)
@@ -48,6 +48,8 @@
 		/* translators: %s: directory name */
 		$this->strings['fs_no_folder'] = __('Unable to locate needed folder (%s).');
 
+		$this->strings['incompatible_archive'] = __('The package is corrupt or not compatible with the system. Please try again.');
+
 		$this->strings['download_failed'] = __('Download failed.');
 		$this->strings['installing_package'] = __('Installing the latest version&#8230;');
 		$this->strings['folder_exists'] = __('Destination folder already exists.');
@@ -153,6 +155,9 @@
 
 		if ( is_wp_error($result) ) {
 			$wp_filesystem->delete($working_dir, true);
+			if ( 'incompatible_archive' == $result->get_error_code() ) {
+				return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], $result->get_error_data() );
+			}
 			return $result;
 		}
 
@@ -624,8 +629,40 @@
 		$this->strings['installing_package'] = __('Installing the theme&#8230;');
 		$this->strings['process_failed'] = __('Theme install failed.');
 		$this->strings['process_success'] = __('Theme installed successfully.');
+		$this->strings['wrong_format'] = __('The provided package is not in the required format.');
 	}
 
+	function unpack_package($package, $delete_package = true) {
+		global $wp_filesystem;
+		$working_dir = parent::unpack_package($package, $delete_package);
+
+		if ( is_wp_error($working_dir) )
+			return $working_dir;
+
+		$problem = false;
+		$dirlist = $wp_filesystem->dirlist( $working_dir );
+		unset( $dirlist[ '__MAC_OSX' ] ); // Some mac archives have a meta directory we need to exclude fromthis check
+		
+		if ( !$dirlist || count($dirlist) > 1 ) { // A proper archive should have a single directory entry
+			$problem = true;
+		} else {
+			$folder = array_shift( array_keys($dirlist) );
+			$dirlist = $wp_filesystem->dirlist( $working_dir . '/' . $folder );
+
+			if ( ! isset($dirlist[ 'style.css' ]) ) // A proper archive should have a style.css file in the single subdirectory
+				$problem = true;
+			// Check file header meta too?
+		}
+
+		// Check the extracted files are in the correct format.
+		if ( $problem ) {
+			$wp_filesystem->delete($working_dir, true);
+			return new WP_Error('wrong_format', $this->strings['wrong_format']);
+		}
+		
+		return $working_dir;
+	}
+
 	function install($package) {
 
 		$this->init();
