BinaryMessagePipe corrupts IPC framing when a message header spans data chunks
Bug
BinaryMessagePipe corrupts IPC framing when its 22-byte header spans data chunks:
- Consecutive short chunks overwrite
partialMessageStart, losing earlier bytes. - If the next chunk completes the header, decoding uses concatenated bytes, but payload offsets still use the original chunk. Payload bytes are lost and the next frame is consumed as payload.
Reproduce
This happens quite often on Windows when large packets are transferred between the backend and the client. It is hard to reproduce consistently, as Windows pipe chunk splitting is arbitrary.
Save as repro.cjs in the repository root and run node repro.cjs with Node.js 24. Uses checked-in parser/codecs; substitutes only the emitter to avoid installing dependencies.
// Run from the repository root with Node.js >= 24:
// node repro.cjs
const { readFileSync } = require('node:fs');
const { stripTypeScriptTypes } = require('node:module');
const { Duplex } = require('node:stream');
const assert = require('node:assert/strict');
// Only the emitter is substituted; parser and codec code come from the checkout.
class Emitter {
listeners = [];
event = listener => {
this.listeners.push(listener);
return { dispose() {} };
};
fire(value) {
for (const listener of this.listeners) {
listener(value);
}
}
dispose() {
this.listeners = [];
}
}
function loadSource(path, bindings, names) {
const source = readFileSync(path, 'utf8')
.replace(/^import .*;\r?$/gm, '')
.replace(/^export /gm, '');
const compiled = stripTypeScriptTypes(source, { mode: 'transform' });
const exportedNames = '\nreturn { ' + names.join(', ') + ' };';
return new Function(...Object.keys(bindings), compiled + exportedNames)(...Object.values(bindings));
}
const codecs = loadSource(
'packages/core/src/common/message-rpc/uint8-array-message-buffer.ts',
{ Emitter }, ['Uint8ArrayReadBuffer', 'Uint8ArrayWriteBuffer']
);
const { BinaryMessagePipe } = loadSource(
'packages/core/src/node/messaging/binary-message-pipe.ts',
{ Emitter, ...codecs }, ['BinaryMessagePipe']
);
const stream = new Duplex({ read() {} });
const pipe = new BinaryMessagePipe(stream);
const receivedMessages = [];
pipe.onMessage(message => receivedMessages.push(Buffer.from(message)));
const payload = Buffer.alloc(64, 0x41);
const header = pipe.encodeMessageStart(payload);
const frame = Buffer.concat([header, payload]);
// Split the 22-byte header after byte 10; deliver the entire remaining frame.
stream.emit('data', frame.subarray(0, 10));
stream.emit('data', frame.subarray(10));
assert.deepEqual(receivedMessages, [payload], 'A complete frame with a split header must deliver its original payload');Expected: the first frame delivers the original 64-byte payload. Actual: the assertion fails because no message is delivered; the parser incorrectly waits for 10 more bytes.
Verified on Windows, Node.js 24.19.0, commit 92529e45beeb2e20cd325c11670e9bf23c38646b.
Related: #17150 has the same framing error and was closed without reproduction; a shared cause is unconfirmed.
Suggested fix: accumulate partial headers before checking length and use the combined buffer consistently for payload offsets.
Source: eclipse-theia/theia