Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

child_process: fix parsing messages with splitted length field #56106

Merged
merged 6 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 6 additions & 1 deletion lib/internal/child_process/serialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@
*parseChannelMessages(channel, readData) {
if (readData.length === 0) return;

ArrayPrototypePush(channel[kMessageBuffer], readData);
if (channel[kMessageBuffer].length && channel[kMessageBuffer][0].length < 4) {
MGorkov marked this conversation as resolved.
Show resolved Hide resolved
// message length splitted into two buffers, so let's concat it

Check failure on line 65 in lib/internal/child_process/serialization.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Comments should not begin with a lowercase character
MGorkov marked this conversation as resolved.
Show resolved Hide resolved
channel[kMessageBuffer][0] = Buffer.concat([channel[kMessageBuffer][0], readData]);
} else {
ArrayPrototypePush(channel[kMessageBuffer], readData);
}
channel[kMessageBufferSize] += readData.length;

// Index 0 should always be present because we just pushed data into it.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'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.nextTick(() => {
process.exit(0);
});

Check failure on line 17 in test/parallel/test-child-process-advanced-serialization-splitted-length-field.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Trailing spaces not allowed
}
})()

Check failure on line 19 in test/parallel/test-child-process-advanced-serialization-splitted-length-field.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Trailing spaces not allowed

Check failure on line 19 in test/parallel/test-child-process-advanced-serialization-splitted-length-field.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing semicolon
MGorkov marked this conversation as resolved.
Show resolved Hide resolved
} else {
const child = child_process.spawn(process.execPath, [__filename, 'child'], {
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
serialization: 'advanced'
});
child.on('message', common.mustCall(cnt));
}
Loading