Skip to content

Commit d8a1cde

Browse files
islandryuaduh95
authored andcommitted
child_process: treat ipc length header as unsigned uint32
Fixes: #61312 PR-URL: #61344 Reviewed-By: Aviv Keller <me@aviv.sh>
1 parent 2a8e8df commit d8a1cde

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

lib/internal/child_process/serialization.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ const advanced = {
7474
while (messageBufferHead.length >= 4) {
7575
// We call `readUInt32BE` manually here, because this is faster than first converting
7676
// it to a buffer and using `readUInt32BE` on that.
77-
const fullMessageSize = (
77+
const fullMessageSize = ((
7878
messageBufferHead[0] << 24 |
7979
messageBufferHead[1] << 16 |
8080
messageBufferHead[2] << 8 |
8181
messageBufferHead[3]
82-
) + 4;
82+
) >>> 0) + 4;
8383

8484
if (channel[kMessageBufferSize] < fullMessageSize) break;
8585

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const { fork } = require('child_process');
5+
const fs = require('fs');
6+
7+
if (process.argv[2] === 'child-buffer') {
8+
const v = process.argv[3];
9+
const payload = Buffer.from([
10+
(v >> 24) & 0xFF,
11+
(v >> 16) & 0xFF,
12+
(v >> 8) & 0xFF,
13+
v & 0xFF,
14+
]);
15+
const fd = process.channel?.fd;
16+
if (fd === undefined) {
17+
// skip test
18+
process.exit(0);
19+
}
20+
fs.writeSync(fd, payload);
21+
return;
22+
}
23+
24+
const testCases = [
25+
0x00000001,
26+
0x7fffffff,
27+
0x80000000,
28+
0x80000001,
29+
0xffffffff,
30+
];
31+
32+
for (const size of testCases) {
33+
const child = fork(__filename, ['child-buffer', size], {
34+
serialization: 'advanced',
35+
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
36+
});
37+
38+
child.on('exit', common.mustCall((code, signal) => {
39+
assert.strictEqual(code, 0);
40+
assert.strictEqual(signal, null);
41+
}));
42+
}

0 commit comments

Comments
 (0)