fix(group-file): correct GroupFileExtra wire shape — server was rejecting with result=79

Two off-by-one bugs in the group-file chat-post element that combined
to make the QQ-NT server reject every group file send with result=79
(visible as "group file uploaded but chat post failed" in the logs):

1. Inner GroupFileInfo fields were shifted one tag left:
   - fileSha    was field 5, should be field 6
   - extInfo    was field 6, should be field 7
   - fileMd5    was field 7, should be field 8
   Field 5 is actually a uint32 placeholder (`field5` in both NapCat
   and acidify). With the bug, our fileSha bytes were landing where
   the server expected a varint and the rest of the message got
   skipped as garbage.

2. Outer GroupFileExtra was missing the magic field1=6 + fileName
   slots that NapCat's encoder writes
   (`packet/message/element.ts:589`). Acidify's schema also models
   them as required even though it serialises with defaults. The
   current server build rejects sends without these slots populated.

Cross-referenced:
- NapCat `GroupFileExtraInfo` (component.ts:146-155) — matches our
  new field numbers exactly
- acidify `GroupFileExtra.Inner.Info` (proto/message/extra/GroupFileExtra.kt)
  — same field numbers; their schema uses generic `field5`/`field7`
  names but the wire layout is identical

Changes:
- Proton + legacy schemas: shift inner fields, add outer field1/
  fileName/display
- `makeGroupFileElem`: write field1=6 + fileName on the outer wrapper
- Regression test asserts each inner tag lands at 50/58/66 (not the
  old 42/50/58) and verifies the new outer field1 + fileName bytes
  are present
This commit is contained in:
DrSmoothl committed 2026-05-19 21:51:35 +08:00
1 parent 04a905460b
commit 8f839f4f30
4 files changed
+100 -7

No files matched your search

@@ -262,7 +262,16 @@ function makeGroupFileElem(element: MessageElement): ProtoElem {
const md5 = element.md5Hex ? hexToBytes(element.md5Hex) : new Uint8Array(0);
const sha1 = element.sha1Hex ? hexToBytes(element.sha1Hex) : new Uint8Array(0);
// Outer field1 is hardcoded to 6 in NapCat's encoder
// (`packet/message/element.ts:589`). It's a magic tag the server
// expects on send (acidify ships the same shape via their generic
// `field1: Int` default but their consumer writes it too). Without
// these outer fields the current QQ-NT server rejects the message
// with `result=79`. Inner field5 is the uint32 placeholder both
// NapCat and acidify leave at 0 — we follow suit.
const extraBytes = protobuf_encode<GroupFileExtra>({
field1: 6,
fileName,
inner: {
info: {
busId: 102,
+13 -3
View File
@@ -390,14 +390,21 @@ export const MsgInfoSchema = {
// --- GroupFileExtra (TransElem type=24) ---
// Field numbers cross-checked against NapCat (component.ts:146) +
// acidify (GroupFileExtra.kt:Inner.Info). Old schema had fileSha at 5
// / extInfoString at 6 / fileMd5 at 7 which mismatched the real wire
// shape — the server rejected the chat post with `result=79` because
// fileSha bytes were landing where it expected a uint32 (field 5).
// See proton/element.ts for the WHY comment.
export const GroupFileInfoSchema = {
busId: { field: 1, type: 'uint32' as const },
fileId: { field: 2, type: 'string' as const },
fileSize: { field: 3, type: 'uint64' as const },
fileName: { field: 4, type: 'string' as const },
fileSha: { field: 5, type: 'bytes' as const },
extInfoString: { field: 6, type: 'string' as const },
fileMd5: { field: 7, type: 'bytes' as const },
field5: { field: 5, type: 'uint32' as const },
fileSha: { field: 6, type: 'bytes' as const },
extInfoString: { field: 7, type: 'string' as const },
fileMd5: { field: 8, type: 'bytes' as const },
} satisfies ProtoSchema;
export const GroupFileExtraInnerSchema = {
@@ -405,6 +412,9 @@ export const GroupFileExtraInnerSchema = {
} satisfies ProtoSchema;
export const GroupFileExtraSchema = {
field1: { field: 1, type: 'uint32' as const },
fileName: { field: 2, type: 'string' as const },
display: { field: 3, type: 'string' as const },
inner: { field: 7, type: 'message' as const, schema: GroupFileExtraInnerSchema },
} satisfies ProtoSchema;
@@ -392,23 +392,43 @@ export interface MsgInfo {
}
// ── GroupFileExtra (TransElem type=24) ──────────────────────────────
//
// Sourced from NapCat's `GroupFileExtraInfo` (component.ts:146-155)
// cross-checked against acidify's `GroupFileExtra.Inner.Info`
// (proto/message/extra/GroupFileExtra.kt). Field numbers had been
// shifted by one in the previous schema (fileSha at 5, ext at 6,
// fileMd5 at 7) which caused the server to reject group-file chat
// posts with `result=79` — the server saw fileSha bytes where it
// expected a uint32 placeholder (field 5) and silently dropped the
// rest. Field 5 is a uint32 placeholder both refs label `field5`;
// fileSha is at 6, extInfoString at 7, fileMd5 at 8.
export interface GroupFileInfo {
busId?: pb<1, uint_32>;
fileId?: pb<2, string>;
fileSize?: pb<3, uint_64>;
fileName?: pb<4, string>;
fileSha?: pb<5, bytes>;
extInfoString?: pb<6, string>;
fileMd5?: pb<7, bytes>;
field5?: pb<5, uint_32>;
fileSha?: pb<6, bytes>;
extInfoString?: pb<7, string>;
fileMd5?: pb<8, bytes>;
}
export interface GroupFileExtraInner {
info?: pb<2, GroupFileInfo>;
}
// Outer wrapper carries three additional fields the server expects:
// field1 (uint32, NapCat hardcodes to 6 — "magic op tag"), fileName
// (string mirror of the inner info.fileName), display (optional UI
// preview string, NapCat leaves empty but writes the slot). Without
// these the server still recognized the message in older builds but
// rejects it in the current rollout.
export interface GroupFileExtra {
inner?: pb<7, GroupFileExtraInner>;
field1?: pb<1, uint_32>;
fileName?: pb<2, string>;
display?: pb<3, string>;
inner?: pb<7, GroupFileExtraInner>;
}
// ── Preserve (for message receipt info) ─────────────────────────────