Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/core/src/services/shellExecutionService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/services/shellExecutionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down
Loading