Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8bbdb12

Browse filesBrowse files
MGorkovaduh95
authored andcommitted
child_process: fix parsing messages with splitted length field
Fixes: #55834 PR-URL: #56106 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 21362cc commit 8bbdb12
Copy full SHA for 8bbdb12

File tree

Expand file treeCollapse file tree

2 files changed

+30
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+30
-1
lines changed
Open diff view settings
Collapse file

‎lib/internal/child_process/serialization.js‎

Copy file name to clipboardExpand all lines: lib/internal/child_process/serialization.js
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ const advanced = {
6161
*parseChannelMessages(channel, readData) {
6262
if (readData.length === 0) return;
6363

64-
ArrayPrototypePush(channel[kMessageBuffer], readData);
64+
if (channel[kMessageBufferSize] && channel[kMessageBuffer][0].length < 4) {
65+
// Message length split into two buffers, so let's concatenate it.
66+
channel[kMessageBuffer][0] = Buffer.concat([channel[kMessageBuffer][0], readData]);
67+
} else {
68+
ArrayPrototypePush(channel[kMessageBuffer], readData);
69+
}
6570
channel[kMessageBufferSize] += readData.length;
6671

6772
// Index 0 should always be present because we just pushed data into it.
Collapse file
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
const common = require('../common');
3+
const child_process = require('child_process');
4+
5+
// Regression test for https://github.com/nodejs/node/issues/55834
6+
const msgLen = 65521;
7+
let cnt = 10;
8+
9+
if (process.argv[2] === 'child') {
10+
const msg = Buffer.allocUnsafe(msgLen);
11+
(function send() {
12+
if (cnt--) {
13+
process.send(msg, send);
14+
} else {
15+
process.disconnect();
16+
}
17+
})();
18+
} else {
19+
const child = child_process.spawn(process.execPath, [__filename, 'child'], {
20+
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
21+
serialization: 'advanced'
22+
});
23+
child.on('message', common.mustCall(cnt));
24+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.