mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-07-10 01:29:17 +00:00
fix(desktop): reject fractional transfer sizes (#5527)
This commit is contained in:
parent
71fd0294e9
commit
0880e34461
2 changed files with 30 additions and 2 deletions
|
|
@ -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' })
|
||||
|
|
|
|||
|
|
@ -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') {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue