Skip to content

parseElements 中 protobuf decode 传入 undefined 导致 dispatch error #799

Description

@cclite123

问题描述

含 markdown 段的群消息触发 dispatch error: Cannot read properties of undefined (reading 'length'),导致消息丢失不上报。

堆栈追踪

TypeError: Cannot read properties of undefined (reading 'length')
    at new CodedReader (@saltify/typeproto/dist/index.mjs:23:24)
    at ProtoMessage.decode (@saltify/typeproto/dist/index.mjs:927:18)
    at parseElements (src/ntqqapi/helper/messageParsing.ts:20:39)
    at convertToRawMessage (src/ntqqapi/dispatcher.ts:850:20)
    at handleChatMessage (src/ntqqapi/dispatcher.ts:781:22)
    at handleMsgPush (src/ntqqapi/dispatcher.ts:107:7)

根因

parseElements 函数中,elem.commonElem.pbElem 可能为 undefined
直接传给 Msg.MarkdownExtra.decode(pbElem) 时,protobuf 库的 CodedReader
构造函数访问 undefined.length 导致崩溃。

复现条件

  • LLOneBot 8.0.3
  • NTQQ 桌面版
  • 官方 bot 发送含 markdown 段的群消息

修复方案

1. parseElements 中 pbElem 空值检查

// src/ntqqapi/helper/messageParsing.ts
const pbElem = elem.commonElem.pbElem;
if (!pbElem) continue;  // 添加此检查

2. TextResvAttr.decode 空值检查

if (isAt && textElem.attr6Buf.length >= 11 && textElem.attr6Buf[6] !== 1) {
    if (!elem.text.pbReserve) continue;  // 添加此检查
    const attr = Msg.TextResvAttr.decode(elem.text.pbReserve);
}

3. parseMsgInfoElement 空值检查

function parseMsgInfoElement(pbElem, bizType) {
    if (!pbElem) return null;  // 添加此检查
    const msgInfo = Media.MsgInfo.decode(pbElem);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions