Skip to content

Commit e3367b4

Browse files
committed
fix(workflow-code): push a node's children one at a time when walking the tree
A node with more children than one call takes as arguments (a wide array literal) threw a RangeError from the spread, in both compile's literal check and the client's codeFile() scan.
1 parent b34b746 commit e3367b4

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎packages/workflow-code/src/code-files/references.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function codeFileReferences(text: string): string[] {
5555
const path = literalText(node.arguments[0])
5656
if (path !== null) paths.add(path)
5757
}
58-
stack.push(...childNodes(node))
58+
for (const child of childNodes(node)) stack.push(child)
5959
}
6060
return [...paths]
6161
}

‎packages/workflow-code/src/compile/characters.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,6 @@ export function checkStorableLiterals(
138138
}
139139
continue
140140
}
141-
stack.push(...childNodes(node))
141+
for (const child of childNodes(node)) stack.push(child)
142142
}
143143
}

‎packages/workflow-code/src/compile/hostile.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { afterEach, describe, expect, it } from 'vitest'
2+
import { codeFileReferences } from '../code-files/references'
23
import type { CompileResult } from './index'
34
import { compileWorkflow } from './index'
45
import { type CompileLimits, sourceDepthOverflow } from './parse'
@@ -349,6 +350,13 @@ describe('one set of limits for get and compile', () => {
349350
expect(sourceDepthOverflow(files, Number.POSITIVE_INFINITY)).toBeNull()
350351
})
351352

353+
it('walks a node with more children than one call can take as arguments', () => {
354+
const wide = `[${'0,'.repeat(300_000)}0]`
355+
const entry = `${HEADER.replace('api, ', 'codeFile, fn, ')}export default workflow('Hostile', {}, () => {\n const f = fn('F', { code: codeFile('./f.js') })\n const a = api('A', { url: 'x', body: raw(${wide}) })\n})\n`
356+
expect(() => run(entry, undefined, { 'workflows/f.js': 'return 1\n' })).not.toThrow()
357+
expect(codeFileReferences(entry)).toEqual(['./f.js'])
358+
})
359+
352360
it('passes a source nested within the cap', () => {
353361
const files = { 'workflows/hostile.ts': entryWith(nested(20)) }
354362
expect(errorCodes(run(files['workflows/hostile.ts']))).not.toContain('E_LIMIT_EXCEEDED')

0 commit comments

Comments
 (0)