Selaa lähdekoodia

Fix out-of-bounds in TypesafeCachedYamlDatabase (#7690)

Fixes #7664

Thanks to @jofvgaming
Vincent Stumpf 2 vuotta sitten
vanhempi
commit
ab6c5beaf8
1 muutettua tiedostoa jossa 10 lisäystä ja 2 poistoa
  1. 10 2
      src/common/database.hpp

+ 10 - 2
src/common/database.hpp

@@ -216,7 +216,11 @@ public:
 
 		// Prevent excessive usage during loading
 		if( this->loaded ){
-			this->cache[this->calculateCacheKey( key )] = nullptr;
+			size_t cache_key = this->calculateCacheKey(key);
+			if (this->cache.size() <= cache_key) {
+				return;
+			}
+			this->cache[cache_key] = nullptr;
 		}
 	}
 
@@ -225,7 +229,11 @@ public:
 
 		// Prevent excessive usage during loading
 		if( this->loaded ){
-			this->cache[this->calculateCacheKey( key )] = ptr;
+			size_t cache_key = this->calculateCacheKey(key);
+			if (this->cache.size() <= cache_key) {
+				this->cache.resize(cache_key + 1, nullptr);
+			}
+			this->cache[cache_key] = ptr;
 		}
 	}
 };