mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
child_process: fix parsing messages with splitted length field
Fixes: https://github.com/nodejs/node/issues/55834 PR-URL: https://github.com/nodejs/node/pull/56106 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
840f952268
commit
009d53ec3c
|
|
@ -61,7 +61,12 @@ const advanced = {
|
||||||
*parseChannelMessages(channel, readData) {
|
*parseChannelMessages(channel, readData) {
|
||||||
if (readData.length === 0) return;
|
if (readData.length === 0) return;
|
||||||
|
|
||||||
|
if (channel[kMessageBufferSize] && channel[kMessageBuffer][0].length < 4) {
|
||||||
|
// Message length split into two buffers, so let's concatenate it.
|
||||||
|
channel[kMessageBuffer][0] = Buffer.concat([channel[kMessageBuffer][0], readData]);
|
||||||
|
} else {
|
||||||
ArrayPrototypePush(channel[kMessageBuffer], readData);
|
ArrayPrototypePush(channel[kMessageBuffer], readData);
|
||||||
|
}
|
||||||
channel[kMessageBufferSize] += readData.length;
|
channel[kMessageBufferSize] += readData.length;
|
||||||
|
|
||||||
// Index 0 should always be present because we just pushed data into it.
|
// Index 0 should always be present because we just pushed data into it.
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
'use strict';
|
||||||
|
const common = require('../common');
|
||||||
|
const child_process = require('child_process');
|
||||||
|
|
||||||
|
// Regression test for https://github.com/nodejs/node/issues/55834
|
||||||
|
const msgLen = 65521;
|
||||||
|
let cnt = 10;
|
||||||
|
|
||||||
|
if (process.argv[2] === 'child') {
|
||||||
|
const msg = Buffer.allocUnsafe(msgLen);
|
||||||
|
(function send() {
|
||||||
|
if (cnt--) {
|
||||||
|
process.send(msg, send);
|
||||||
|
} else {
|
||||||
|
process.disconnect();
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
} else {
|
||||||
|
const child = child_process.spawn(process.execPath, [__filename, 'child'], {
|
||||||
|
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
|
||||||
|
serialization: 'advanced'
|
||||||
|
});
|
||||||
|
child.on('message', common.mustCall(cnt));
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user