diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc
index f34c766..4ca15cd 100644
--- a/core/modules/system/system.admin.inc
+++ b/core/modules/system/system.admin.inc
@@ -7,6 +7,7 @@
 
 use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
 
 /**
  * Menu callback; Provide the administration overview page.
@@ -372,8 +373,11 @@ function system_theme_default() {
 function system_theme_settings($form, &$form_state, $key = '') {
   // Default settings are defined in theme_get_setting() in includes/theme.inc
   if ($key) {
-    $var = 'theme_' . $key . '_settings';
     $themes = list_themes();
+    if (!array_key_exists($key, $themes)) {
+      throw new NotFoundHttpException();
+    }
+    $var = 'theme_' . $key . '_settings';
     $features = $themes[$key]->info['features'];
   }
   else {
