N°6618 - Router: Add protection against invalid routes cache

This commit is contained in:
Molkobain
2023-08-01 21:57:04 +02:00
parent a5c980113b
commit 85f66f5e0c
2 changed files with 51 additions and 4 deletions

View File

@@ -144,7 +144,16 @@ class Router
// Try to read from cache
if ($bUseCache) {
if (is_file($sCacheFilePath)) {
$aRoutes = include $sCacheFilePath;
$aCachedRoutes = include $sCacheFilePath;
// N°6618 - Protection against corrupted cache returning `1` instead of an array of routes
if (is_array($aCachedRoutes)) {
$aRoutes = $aCachedRoutes;
} else {
// Invalid cache force re-generation
// Note that even if it is re-generated corrupted again, this protection should prevent crashes
$bMustWriteCache = true;
}
} else {
$bMustWriteCache = true;
}