Check for invalid utf8 better

This commit is contained in:
Mm2PL 2023-02-04 01:25:58 +01:00
parent e331e49310
commit 760ec89e07
No known key found for this signature in database
GPG key ID: 94AC9B80EFA15ED9

View file

@ -105,10 +105,13 @@ static const QChar REPLACEMENT_CHARACTER = QChar(0xFFFD);
int g_load(lua_State *L) int g_load(lua_State *L)
{ {
auto countArgs = lua_gettop(L); auto countArgs = lua_gettop(L);
QString str; QByteArray data;
if (lua::peek(L, &str, 1)) 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 // NOLINTNEXTLINE
luaL_error(L, "invalid utf-8 in load() is not allowed"); luaL_error(L, "invalid utf-8 in load() is not allowed");