fix(core): remove buffer slice to prevent OOM on large output streams (#25094)

This commit is contained in:
Spencer
2026-04-10 12:33:36 -04:00
committed by GitHub
parent c1fd6027e2
commit f6c08a114b
2 changed files with 18 additions and 2 deletions

View File

@@ -1610,6 +1610,22 @@ describe('ShellExecutionService child_process fallback', () => {
'exit',
]);
});
it('should correctly measure sniffedBytes with >20 small chunks to prevent OOM (regression #22170)', async () => {
mockIsBinary.mockReturnValue(false);
await simulateExecution('cat lots_of_chunks', (cp) => {
for (let i = 0; i < 25; i++) {
cp.stdout?.emit('data', Buffer.alloc(10, 'a'));
}
cp.emit('exit', 0, null);
cp.emit('close', 0, null);
});
const lastCallBuffer =
mockIsBinary.mock.calls[mockIsBinary.mock.calls.length - 1][0];
expect(lastCallBuffer.length).toBe(250);
});
});
describe('Platform-Specific Behavior', () => {

View File

@@ -630,7 +630,7 @@ export class ShellExecutionService {
}
if (isStreamingRawContent && sniffedBytes < MAX_SNIFF_SIZE) {
const sniffBuffer = Buffer.concat(state.sniffChunks.slice(0, 20));
const sniffBuffer = Buffer.concat(state.sniffChunks);
sniffedBytes = sniffBuffer.length;
if (isBinary(sniffBuffer)) {
@@ -1094,7 +1094,7 @@ export class ShellExecutionService {
}
if (isStreamingRawContent && sniffedBytes < MAX_SNIFF_SIZE) {
const sniffBuffer = Buffer.concat(sniffChunks.slice(0, 20));
const sniffBuffer = Buffer.concat(sniffChunks);
sniffedBytes = sniffBuffer.length;
if (isBinary(sniffBuffer)) {