From 20f48d11ec8bc7765c383891a4a7021c8b30b9ae Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Tue, 13 Oct 2026 09:48:00 +0800 Subject: [PATCH] fix(core): accept large integers in album responses Allow valid album responses with large integer values to reach the comment request and add regression coverage. Refs #508 --- packages/core/src/bridge/apis/group-album.ts | 18 +++++++++++++- .../core/tests/actions/group-album.test.ts | 24 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/packages/core/src/bridge/apis/group-album.ts b/packages/core/src/bridge/apis/group-album.ts index 1a1a3809..dd219688 100644 --- a/packages/core/src/bridge/apis/group-album.ts +++ b/packages/core/src/bridge/apis/group-album.ts @@ -879,6 +879,22 @@ function readProtobufVarint(buf: Uint8Array, offset: number): { value: number; n throw new Error('truncated protobuf varint'); } +function skipProtobufVarint(buf: Uint8Array, offset: number): number { + for (let index = 0; index < 10 && offset < buf.length; index++) { + const byte = buf[offset++]; + + if (index === 9 && byte > 1) { + throw new Error('protobuf varint exceeds 64 bits'); + } + + if ((byte & 0x80) === 0) { + return offset; + } + } + + throw new Error('truncated protobuf varint'); +} + function protobufSubmessage(buf: Uint8Array, path: readonly number[]): Uint8Array | undefined { let current: Uint8Array | undefined = buf; @@ -903,7 +919,7 @@ function firstLengthDelimitedField(buf: Uint8Array, fieldNo: number): Uint8Array const wire = key.value % 8; if (wire === 0) { - offset = readProtobufVarint(buf, offset).next; + offset = skipProtobufVarint(buf, offset); } else if (wire === 1) { offset += 8; } else if (wire === 5) { diff --git a/packages/core/tests/actions/group-album.test.ts b/packages/core/tests/actions/group-album.test.ts index b7e861c5..4bcaa446 100644 --- a/packages/core/tests/actions/group-album.test.ts +++ b/packages/core/tests/actions/group-album.test.ts @@ -953,6 +953,30 @@ describe('apis/group-album', () => { ); }); + it.each([ + { name: 'six-byte', value: [0x80, 0x80, 0x80, 0x80, 0x80, 0x20] }, + { name: 'ten-byte', value: [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01] }, + ])('accepts a $name unknown integer before the feed data', async ({ value }) => { + const packed = packFeedDetail('official-feed-id', 1700000123n, { ownerUin: '10002' }); + const responseData = Buffer.from( + concatBytes([new Uint8Array([0x30, ...value]), new Uint8Array(packed.responseData)]), + ); + expect( + protobuf_decode(responseData).data?.feed?.feed?.cellCommon + ?.feedId, + ).toBe('official-feed-id'); + const bridge = mockBridge(); + bridge.sendRawPacket.mockImplementation( + commentMocks((cmd) => + cmd.endsWith('GetQunFeedDetail') ? { ...packed, responseData } : undefined, + ), + ); + + await expect( + new GroupAlbumApi(bridge as never).comment(12345, 'album-id', 'photo-lloc', 'hello'), + ).resolves.toMatchObject({ id: 'cmt-1' }); + }); + it('copies an unknown media-cell field through unchanged', async () => { const packed = packFeedDetail('official-feed-id', 1700000123n, { ownerUin: '3119936551',