diff --git a/src/Composer/DependencyResolver/Problem.php b/src/Composer/DependencyResolver/Problem.php
index e199110ee..560fbb5dd 100644
--- a/src/Composer/DependencyResolver/Problem.php
+++ b/src/Composer/DependencyResolver/Problem.php
@@ -95,6 +95,12 @@ class Problem
                     return "\n    - The requested linked library ".$job['packageName'].$this->constraintToText($job['constraint']).' has the wrong version installed or is missing from your system, make sure to have the extension providing it.';
                 }
 
+                if (!preg_match('{^[A-Za-z0-9_./-]+$}', $job['packageName'])) {
+                    $illegalChars = preg_replace('{[A-Za-z0-9_./-]+}', '', $job['packageName']);
+
+                    return "\n    - The requested package ".$job['packageName'].' could not be found, it looks like its name is invalid, "'.$illegalChars.'" is not allowed in package names.';
+                }
+
                 if (!$this->pool->whatProvides($job['packageName'])) {
                     return "\n    - The requested package ".$job['packageName'].' could not be found in any version, there may be a typo in the package name.';
                 }
diff --git a/src/Composer/Package/Loader/ValidatingArrayLoader.php b/src/Composer/Package/Loader/ValidatingArrayLoader.php
index 25d1109a4..87ce0036d 100644
--- a/src/Composer/Package/Loader/ValidatingArrayLoader.php
+++ b/src/Composer/Package/Loader/ValidatingArrayLoader.php
@@ -145,6 +145,9 @@ class ValidatingArrayLoader implements LoaderInterface
         foreach (array_keys(BasePackage::$supportedLinkTypes) as $linkType) {
             if ($this->validateArray($linkType) && isset($this->config[$linkType])) {
                 foreach ($this->config[$linkType] as $package => $constraint) {
+                    if (!preg_match('{^[A-Za-z0-9_./-]+$}', $package)) {
+                        $this->warnings[] = $linkType.'.'.$package.' : invalid key, package names must be strings containing only [A-Za-z0-9_./-]';
+                    }
                     if (!is_string($constraint)) {
                         $this->errors[] = $linkType.'.'.$package.' : invalid value, must be a string containing a version constraint';
                         unset($this->config[$linkType][$package]);