fix(desktop): reject fractional transfer sizes (#5527)

This commit is contained in:
tt-a1i 2026-06-21 13:05:52 +08:00 committed by GitHub
parent 71fd0294e9
commit 0880e34461
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 2 deletions

View file

@ -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' })

View file

@ -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') {