From 0880e3446152ea259650f76a303020ff8080448b Mon Sep 17 00:00:00 2001 From: tt-a1i <53142663+tt-a1i@users.noreply.github.com> Date: Sun, 21 Jun 2026 13:05:52 +0800 Subject: [PATCH] fix(desktop): reject fractional transfer sizes (#5527) --- .../src/handlers/rpc/transfer.test.ts | 28 +++++++++++++++++++ .../server-core/src/handlers/rpc/transfer.ts | 4 +-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/desktop/packages/server-core/src/handlers/rpc/transfer.test.ts b/packages/desktop/packages/server-core/src/handlers/rpc/transfer.test.ts index c350f8db0e..29a4d86c34 100644 --- a/packages/desktop/packages/server-core/src/handlers/rpc/transfer.test.ts +++ b/packages/desktop/packages/server-core/src/handlers/rpc/transfer.test.ts @@ -65,6 +65,34 @@ afterEach(() => { }) describe('chunked transfer handlers', () => { + it('rejects fractional chunk counts', async () => { + const { start } = createHarness() + + setTransferableHandler('test:echo', async (_ctx, _placeholder, body) => body) + + await expect(start(ctx('client-1'), { + totalBytes: 10, + chunkCount: 1.5, + channel: 'test:echo', + args: [null, null], + largeArgIndex: 1, + })).rejects.toThrow('Invalid chunkCount') + }) + + it('rejects fractional total byte counts', async () => { + const { start } = createHarness() + + setTransferableHandler('test:echo', async (_ctx, _placeholder, body) => body) + + await expect(start(ctx('client-1'), { + totalBytes: 10.5, + chunkCount: 1, + channel: 'test:echo', + args: [null, null], + largeArgIndex: 1, + })).rejects.toThrow('Invalid totalBytes') + }) + it('rejects chunk uploads from a different client', async () => { const { start, chunk } = createHarness() const payload = encodeParts({ hello: 'world' }) diff --git a/packages/desktop/packages/server-core/src/handlers/rpc/transfer.ts b/packages/desktop/packages/server-core/src/handlers/rpc/transfer.ts index e0cd960fa9..a8006a3562 100644 --- a/packages/desktop/packages/server-core/src/handlers/rpc/transfer.ts +++ b/packages/desktop/packages/server-core/src/handlers/rpc/transfer.ts @@ -98,10 +98,10 @@ export function registerTransferHandlers(server: RpcServer): void { largeArgIndex: number checksum?: string }) => { - if (!opts || typeof opts.chunkCount !== 'number' || opts.chunkCount < 1) { + if (!opts || !Number.isInteger(opts.chunkCount) || opts.chunkCount < 1) { throw new Error('Invalid chunkCount') } - if (typeof opts.totalBytes !== 'number' || opts.totalBytes < 0) { + if (!Number.isInteger(opts.totalBytes) || opts.totalBytes < 0) { throw new Error('Invalid totalBytes') } if (!opts.channel || typeof opts.channel !== 'string') {