fix(protocol): preserve member operation high bits

Clear only the membership flag bit when normalizing group increase operation codes so unrelated high bits cannot collapse into the invitation value.

Add regression coverage for extended operation codes.
This commit is contained in:
DrSmoothl committed 2026-07-16 20:17:38 +08:00
1 parent 0e3bbc6906
commit c2d028af2e
2 files changed
+17 -5

No files matched your search

@@ -181,9 +181,20 @@ describe('parseMsgPush group member increase', () => {
), ),
identity, identity,
) as GroupMemberJoin[]; ) as GroupMemberJoin[];
const [unknownHighBits] = parseMsgPush(
makeGroupIncreasePacket(
member.uid,
operator.uid,
GROUP_ID,
Buffer.from(operator.uid, 'utf8'),
0x103,
),
identity,
) as GroupMemberJoin[];
expect(approved.joinType).toBe('approve'); expect(approved.joinType).toBe('approve');
expect(invited.joinType).toBe('invite'); expect(invited.joinType).toBe('invite');
expect(unknownHighBits.joinType).toBe('approve');
}); });
it('reports malformed raw operator bytes with bounded context', () => { it('reports malformed raw operator bytes with bounded context', () => {
@@ -5,11 +5,12 @@ import { decodeNestedOperatorUid, decodeRawOperatorUid, resolveUidToUin } from '
import type { MsgPushDecoder } from '../registry'; import type { MsgPushDecoder } from '../registry';
function joinTypeFromOperationType(raw: number): NonNullable<GroupMemberJoin['joinType']> { function joinTypeFromOperationType(raw: number): NonNullable<GroupMemberJoin['joinType']> {
// QQ sets the high bit on the PkgType=33 operation code. After normalizing // QQ uses bit 0x80 as a flag on the PkgType=33 operation code. Clear only
// it, code 3 means an invitation; code 2 (and unknown/absent values) means // that bit: other high bits remain significant in the native handler. The
// approval. Do not use the nested `join_type`: that is an invitation-source // normalized code 3 means an invitation; all other values mean approval.
// enum rather than OneBot's approve/invite distinction. // Do not use the nested `join_type`: that is an invitation-source enum.
return (raw & 0x7f) === 3 ? 'invite' : 'approve'; const normalized = raw - (raw & 0x80);
return normalized === 3 ? 'invite' : 'approve';
} }
export const decodeGroupMemberJoin: MsgPushDecoder = (ctx) => { export const decodeGroupMemberJoin: MsgPushDecoder = (ctx) => {