Skip to content
This repository was archived by the owner on Apr 29, 2024. It is now read-only.

Commit 7579e3a

Browse files
authored
Do not crash when encountering invalid characters (#480)
* Do not crash when encountering invalid character * Add missing <format> include * Use fmt::format for now
1 parent f359f33 commit 7579e3a

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/libs/renderer/src/font.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#include "font.h"
22
#include "core.h"
3+
#include "storm/config.hpp"
34
#include "utf8.h"
45

6+
#include <fmt/format.h>
7+
58
namespace
69
{
710

@@ -201,7 +204,14 @@ int32_t FONT::GetStringWidth(const std::string_view &text, std::optional<float>
201204
for (int32_t i = 0; i < s_num; i += utf8::u8_inc(text.data() + i))
202205
{
203206
uint32_t Codepoint = utf8::Utf8ToCodepoint(text.data() + i);
204-
Assert(Codepoint < USED_CODES);
207+
208+
if (Codepoint > USED_CODES) {
209+
core.Trace("Invalid codepoint: %d", Codepoint);
210+
if constexpr(storm::kIsDebug) {
211+
throw std::runtime_error(fmt::format("Invalid codepoint: {}", Codepoint));
212+
}
213+
continue;
214+
}
205215

206216
FLOAT_RECT pos = charDescriptors_[Codepoint].Pos;
207217

@@ -238,7 +248,14 @@ int32_t FONT::UpdateVertexBuffer(int32_t x, int32_t y, char *data_PTR, int utf8l
238248
Assert(curLetter < utf8length);
239249

240250
int Codepoint = utf8::Utf8ToCodepoint(data_PTR + i);
241-
Assert(Codepoint < USED_CODES);
251+
252+
if (Codepoint > USED_CODES) {
253+
core.Trace("Invalid codepoint: %d", Codepoint);
254+
if constexpr(storm::kIsDebug) {
255+
throw std::runtime_error(fmt::format("Invalid codepoint: {}", Codepoint));
256+
}
257+
continue;
258+
}
242259

243260
n = curLetter * 6;
244261
FLOAT_RECT pos = charDescriptors_[Codepoint].Pos;

0 commit comments

Comments
 (0)