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

Fixes #7664

Thanks to @jofvgaming
This commit is contained in:
Vincent Stumpf 2023-04-09 12:49:30 -07:00 committed by GitHub
parent d2e972cfd1
commit ab6c5beaf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
}
}
};