Skip to content
Open
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
4 changes: 2 additions & 2 deletions lib/internal/child_process/serialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ const advanced = {
while (messageBufferHead.length >= 4) {
// We call `readUInt32BE` manually here, because this is faster than first converting
// it to a buffer and using `readUInt32BE` on that.
const fullMessageSize = (
const fullMessageSize = ((
messageBufferHead[0] << 24 |
messageBufferHead[1] << 16 |
messageBufferHead[2] << 8 |
messageBufferHead[3]
) + 4;
) >>> 0) + 4;

if (channel[kMessageBufferSize] < fullMessageSize) break;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const { fork } = require('child_process');
const fs = require('fs');

if (process.argv[2] === 'child-buffer') {
const v = process.argv[3];
const payload = Buffer.from([
(v >> 24) & 0xFF,
(v >> 16) & 0xFF,
(v >> 8) & 0xFF,
v & 0xFF,
]);
const fd = process.channel?.fd;
if (fd === undefined) {
// skip test
process.exit(0);
}
fs.writeSync(fd, payload);
return;
}

const testCases = [
0x00000001,
0x7fffffff,
0x80000000,
0x80000001,
0xffffffff,
];

for (const size of testCases) {
const child = fork(__filename, ['child-buffer', size], {
serialization: 'advanced',
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
});

child.on('exit', common.mustCall((code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
}));
}
Loading