fix(launcher): app 显示名缓冲 name[17]→[49] + json_str 截断 UTF-8 整序列保护(同 amsd 修复,M6.2 备料 launcher 03dfcf76)

This commit is contained in:
AskaEth committed 2026-09-02 02:20:06 +08:00
1 parent 8588a6b453
commit 54a6e828b7
3 files changed
+33 -6

No files matched your search

+20 -2
View File
@@ -515,9 +515,26 @@ static int ident_ch(char c)
}
/* 把字符串末尾不完整的 UTF-8 序列砍掉(截断到最后一个完整码点边界)。
* 根因记录:显示名按字节截断若落在多字节序列中间,下游(面板 JSON/绘制)
* 会拿到非法 UTF-8(amsd「流媒体客户端」事故 2026-09-02)。 */
static void utf8_trim_incomplete(char *s)
{
size_t n = strlen(s), i = 0, last_good = 0;
while (i < n) {
unsigned char c = (unsigned char)s[i];
int len = (c < 0x80) ? 1 : (c >= 0xF0) ? 4 : (c >= 0xE0) ? 3 : (c >= 0xC0) ? 2 : 1;
if (i + (size_t)len > n) break;
i += (size_t)len;
last_good = i;
}
s[last_good] = '\0';
}
/* 极简 JSON/扁平值提取:在一行里找 key,读取其值(跳过 ':'/'=' 与可选引号)。
* 支持 JSON `"name": "Hello"` 与扁平 `framework=true`。返回拷贝到 out 的字符数。
* 返回 0=未命中/空。 */
* 返回 0=未命中/空。截断做 UTF-8 整序列保护。 */
int json_str(const char *buf, const char *key, char *out, int olen)
{
out[0] = 0;
@@ -535,7 +552,8 @@ int json_str(const char *buf, const char *key, char *out, int olen)
out[i++] = *p++;
out[i] = 0;
while (i > 0 && (out[i - 1] == ' ' || out[i - 1] == '\t')) out[--i] = 0;
return i;
utf8_trim_incomplete(out);
return (int)strlen(out);
}