Refactor font loading logic in LoadSystemFonts function
- Improved buffer size calculations for font name and data to enhance safety and prevent overflow. - Streamlined the maximum font loading limit to ensure efficient font management while maintaining clarity in the code.
This commit is contained in:
@@ -251,14 +251,17 @@ void LoadSystemFonts() {
|
|||||||
|
|
||||||
if (result == ERROR_SUCCESS && valueCount > 0) {
|
if (result == ERROR_SUCCESS && valueCount > 0) {
|
||||||
// Allocate buffers with proper size limits
|
// Allocate buffers with proper size limits
|
||||||
const size_t maxNameSize = (std::min)(static_cast<size_t>(maxValueNameSize) + 1, size_t(1024));
|
size_t maxNameSize = maxValueNameSize + 1;
|
||||||
const size_t maxDataSize = (std::min)(static_cast<size_t>(maxValueDataSize) + 1, size_t(4096));
|
if (maxNameSize > 1024) maxNameSize = 1024;
|
||||||
|
size_t maxDataSize = maxValueDataSize + 1;
|
||||||
|
if (maxDataSize > 4096) maxDataSize = 4096;
|
||||||
|
|
||||||
std::vector<char> valueName(maxNameSize);
|
std::vector<char> valueName(maxNameSize);
|
||||||
std::vector<BYTE> valueData(maxDataSize);
|
std::vector<BYTE> valueData(maxDataSize);
|
||||||
|
|
||||||
// Enumerate font entries (limit to prevent excessive loading)
|
// Enumerate font entries (limit to prevent excessive loading)
|
||||||
const DWORD maxFontsToLoad = (std::min)(valueCount, DWORD(50));
|
DWORD maxFontsToLoad = valueCount;
|
||||||
|
if (maxFontsToLoad > 50) maxFontsToLoad = 50;
|
||||||
|
|
||||||
for (DWORD i = 0; i < maxFontsToLoad; i++) {
|
for (DWORD i = 0; i < maxFontsToLoad; i++) {
|
||||||
DWORD valueNameSize = static_cast<DWORD>(maxNameSize);
|
DWORD valueNameSize = static_cast<DWORD>(maxNameSize);
|
||||||
|
|||||||
Reference in New Issue
Block a user