Skip to content
Snippets Groups Projects
Commit 0e20f584 authored by Helmut Hummel's avatar Helmut Hummel Committed by Ernesto Baschny
Browse files

[BUGFIX] ClassLoader exits early for invalid class names

Instead of doing calculations if an invalid
class name could still be found and implementing
safeguards that our caching layer does not
fail with invalid identifiers, we exit early
if we find an invalid class name.

Maybe PHP will be smart enough at some point
not calling an autoloader at all if the class name
is invalid anyway so we could the remove this check.

By doing a comprehensive check upfront, we can
remove the safeguard code for the caching layer.

The performance impact of this change breaks down
to be lower than 1ms for a regular TYPO3 request.

Resolves: #57183
Releases: 6.2
Change-Id: Id38bea6b85fbfd280417adca325411410cd9fb63
Reviewed-on: https://review.typo3.org/28553
Reviewed-by: Thomas Maroschik
Reviewed-by: Sebastian Fischer
Reviewed-by: Alexander Stehlik
Reviewed-by: Markus Klein
Tested-by: Markus Klein
Reviewed-by: Alexander Opitz
Tested-by: Alexander Opitz
Reviewed-by: Ernesto Baschny
Tested-by: Ernesto Baschny
parent 0681f84f
No related merge requests found
......@@ -38,6 +38,8 @@ use TYPO3\CMS\Core\Cache;
*/
class ClassLoader {
const VALID_CLASSNAME_PATTERN = '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9\\\\_\x7f-\xff]*$/';
/**
* @var ClassAliasMap
*/
......@@ -204,14 +206,10 @@ class ClassLoader {
* - NULL if the cache identifier is invalid (cache failure)
*
* @param string $cacheEntryIdentifier The identifier to fetch entry from cache
* @return array|FALSE|NULL The class information, empty array if class is unkown or FALSE if class information was not found in cache. NULL if a cache identifier is invalid.
* @return array|FALSE The class information, empty array if class is unkown or FALSE if class information was not found in cache.
*/
public function getClassLoadingInformationFromCache($cacheEntryIdentifier) {
try {
$rawClassLoadingInformation = $this->classesCache->get($cacheEntryIdentifier);
} catch (\InvalidArgumentException $exception) {
return NULL;
}
$rawClassLoadingInformation = $this->classesCache->get($cacheEntryIdentifier);
if ($rawClassLoadingInformation === '') {
return array();
......@@ -232,7 +230,7 @@ class ClassLoader {
* @param string $cacheEntryIdentifier Cache identifier for this class
* @param string $className Name of class this information is for
*
* @return array|FALSE|NULL The class information, empty array if class is unkown or FALSE if class information was not found in cache. NULL if a cache identifier is invalid.
* @return array|FALSE The class information, empty array if class is unkown or FALSE if class information was not found in cache.
*/
protected function buildCachedClassLoadingInformation($cacheEntryIdentifier, $className) {
// We do not need locking if we are in earlyCache mode
......@@ -298,7 +296,7 @@ class ClassLoader {
* @return bool
*/
protected function isValidClassName($className) {
return strpos($className, ' ') === FALSE;
return (bool)preg_match(self::VALID_CLASSNAME_PATTERN, $className);
}
/**
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment