Explorar o código

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

Fixes #7664

Thanks to @jofvgaming
Vincent Stumpf %!s(int64=2) %!d(string=hai) anos
pai
achega
ab6c5beaf8
Modificáronse 1 ficheiros con 10 adicións e 2 borrados
  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;
 		}
 	}
 };