From 760ec89e07f55ba74845932e42ea8058c4e142d6 Mon Sep 17 00:00:00 2001 From: Mm2PL Date: Sat, 4 Feb 2023 01:25:58 +0100 Subject: [PATCH] Check for invalid utf8 better --- src/controllers/plugins/ApiChatterino.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/controllers/plugins/ApiChatterino.cpp b/src/controllers/plugins/ApiChatterino.cpp index f008d24ed..18b23a648 100644 --- a/src/controllers/plugins/ApiChatterino.cpp +++ b/src/controllers/plugins/ApiChatterino.cpp @@ -105,10 +105,13 @@ static const QChar REPLACEMENT_CHARACTER = QChar(0xFFFD); int g_load(lua_State *L) { auto countArgs = lua_gettop(L); - QString str; - if (lua::peek(L, &str, 1)) + QByteArray data; + if (lua::peek(L, &data, 1)) { - if (str.contains(REPLACEMENT_CHARACTER)) + auto *utf8 = QTextCodec::codecForName("UTF-8"); + QTextCodec::ConverterState state; + utf8->toUnicode(data.constData(), data.size(), &state); + if (state.invalidChars != 0) { // NOLINTNEXTLINE luaL_error(L, "invalid utf-8 in load() is not allowed");