From 4cc277a818863924d2d99b4793183a1168de12eb Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Fri, 22 May 2020 13:34:43 +0200 Subject: [PATCH] Prevent infinite loop for nested language items (#3299) * Prevent infinite loop for nested language items Close #3163 * Improve exception message in Language::loadCategory() Co-authored-by: Alexander Ebert Co-authored-by: Alexander Ebert --- .../files/lib/data/language/Language.class.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/wcfsetup/install/files/lib/data/language/Language.class.php b/wcfsetup/install/files/lib/data/language/Language.class.php index 448bac6df0..ec8d2ea38a 100644 --- a/wcfsetup/install/files/lib/data/language/Language.class.php +++ b/wcfsetup/install/files/lib/data/language/Language.class.php @@ -46,6 +46,12 @@ class Language extends DatabaseObject { */ public $packageID = PACKAGE_ID; + /** + * contains categories currently being loaded as array keys + * @var bool[] + */ + protected $categoriesBeingLoaded = []; + /** * Returns the name of this language. * @@ -210,6 +216,10 @@ class Language extends DatabaseObject { // search language file $filename = WCF_DIR.'language/'.$this->languageID.'_'.$category.'.php'; if (!@file_exists($filename)) { + if (isset($this->categoriesBeingLoaded[$category])) { + throw new \LogicException("Circular dependency detected! Cannot load category '{$category}' while it is already being loaded."); + } + if ($this->editor === null) { $this->editor = new LanguageEditor($this); } @@ -220,7 +230,11 @@ class Language extends DatabaseObject { return false; } + $this->categoriesBeingLoaded[$category] = true; + $this->editor->updateCategory($languageCategory); + + unset($this->categoriesBeingLoaded[$category]); } // include language file -- 2.20.1