mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-22 17:49:43 +01:00
Fix loading font .txt files that contain null bytes
An example is Maximally Misleading Miserable Misadventure, which has a font.txt which includes all ASCII characters starting with a 0x00 byte. This would accidentally null-terminate the string too early. Instead, we now use the total length of the file again, and keep getting the next UTF-8 codepoint until the file ends. We still need to null-terminate it - it protects against incomplete sequences getting the UTF-8 decoder to read out of bounds.
This commit is contained in:
parent
df577c59ef
commit
79f5e7a05c
1 changed files with 7 additions and 3 deletions
|
@ -344,18 +344,22 @@ static uint8_t load_font(FontContainer* container, const char* name)
|
|||
bool charset_loaded = false;
|
||||
bool special_loaded = false;
|
||||
unsigned char* charmap = NULL;
|
||||
size_t length;
|
||||
if (FILESYSTEM_areAssetsInSameRealDir(name_png, name_txt))
|
||||
{
|
||||
FILESYSTEM_loadAssetToMemory(name_txt, &charmap, NULL, true);
|
||||
/* The .txt can contain null bytes, but it's still null-terminated - it protects
|
||||
* against incomplete sequences getting the UTF-8 decoder to read out of bounds. */
|
||||
FILESYSTEM_loadAssetToMemory(name_txt, &charmap, &length, true);
|
||||
}
|
||||
if (charmap != NULL)
|
||||
{
|
||||
// We have a .txt! It's an obsolete system, but it takes priority if the file exists.
|
||||
const char* current = (char*) charmap;
|
||||
const char* end = (char*) charmap + length;
|
||||
int pos = 0;
|
||||
uint32_t codepoint;
|
||||
while ((codepoint = UTF8_next(¤t)))
|
||||
while (current < end)
|
||||
{
|
||||
uint32_t codepoint = UTF8_next(¤t);
|
||||
add_glyphinfo(f, codepoint, pos);
|
||||
++pos;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue