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
This commit is contained in:
2 files changed
+41
-1
No files matched your search
@@ -879,6 +879,22 @@ function readProtobufVarint(buf: Uint8Array, offset: number): { value: number; n
|
|||||||
throw new Error('truncated protobuf varint');
|
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 {
|
function protobufSubmessage(buf: Uint8Array, path: readonly number[]): Uint8Array | undefined {
|
||||||
let current: Uint8Array | undefined = buf;
|
let current: Uint8Array | undefined = buf;
|
||||||
|
|
||||||
@@ -903,7 +919,7 @@ function firstLengthDelimitedField(buf: Uint8Array, fieldNo: number): Uint8Array
|
|||||||
const wire = key.value % 8;
|
const wire = key.value % 8;
|
||||||
|
|
||||||
if (wire === 0) {
|
if (wire === 0) {
|
||||||
offset = readProtobufVarint(buf, offset).next;
|
offset = skipProtobufVarint(buf, offset);
|
||||||
} else if (wire === 1) {
|
} else if (wire === 1) {
|
||||||
offset += 8;
|
offset += 8;
|
||||||
} else if (wire === 5) {
|
} else if (wire === 5) {
|
||||||
|
|||||||
@@ -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<GetQunFeedDetailResponse>(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 () => {
|
it('copies an unknown media-cell field through unchanged', async () => {
|
||||||
const packed = packFeedDetail('official-feed-id', 1700000123n, {
|
const packed = packFeedDetail('official-feed-id', 1700000123n, {
|
||||||
ownerUin: '3119936551',
|
ownerUin: '3119936551',
|
||||||
|
|||||||
Reference in new issue
Block a user