send image succ

This commit is contained in:
yincong
2026-01-12 14:46:10 +08:00
parent 377a5bdd0d
commit 5fa73bf622
2 changed files with 205 additions and 163 deletions
+30 -2
View File
@@ -445,7 +445,7 @@ function setReceiver() {
let contentLenPtr = receiverStrPtr.add(receiverLen).add(6);
// 判断是否等于 0x77 ('w'), 如果是,则是短字段
if (contentLenPtr.readU8() === 0x77) {
if (isPrintableOrChinese(contentLenPtr, 1)) {
contentLenPtr = contentLenPtr.add(-1);
}
const contentLenValue = readVarint(contentLenPtr)
@@ -536,4 +536,32 @@ function readVarint(addr) {
rpc.exports = {
manualTrigger: manualTrigger
};
};
function isPrintableOrChinese(startPtr, maxScanLength) {
let offset = 0;
while (offset < maxScanLength) {
let b = startPtr.add(offset).readU8();
if (b === 0) {
// 扫描到 \0,且之前没有发现异常字节
return offset > 0; // 如果第一个就是 \0,视为非字符串(可能是空指针)
}
// 判定逻辑:
// 1. 可见 ASCII (32-126) 或 换行/制表符 (9, 10, 13)
let isAscii = (b >= 32 && b <= 126) || (b === 9 || b === 10 || b === 13);
// 2. 汉字 UTF-8 特征:第一个字节通常 >= 0x80 (128)
// 严谨点:UTF-8 汉字首字节通常在 0xE4-0xE9 之间,后续字节在 0x80-0xBF 之间
// 这里简化处理:如果是高位字符,我们暂时放行,由 readUtf8String 最终处理
let isHighBit = (b >= 0x80);
if (!isAscii && !isHighBit) {
// 发现既不是 ASCII 也不是高位字节(如 0x01-0x1F 的控制字符),判定为指针
return false;
}
offset++;
}
return true;
}