Skip to content

Commit f0218e7

Browse files
committed
test: do not hardcode V8 serialization header
The header changes when V8 is updated. Do not hardcode it to avoid breaking V8 updates. Signed-off-by: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 47595e5 commit f0218e7

1 file changed

Lines changed: 21 additions & 16 deletions

File tree

‎test/parallel/test-runner-v8-deserializer.mjs‎

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,37 +39,42 @@ const oversizedLengthStdout = String.fromCharCode(oversizedLengthHeader[0]) +
3939
Buffer.from(oversizedLengthHeader.subarray(1)).toString('utf-8');
4040
const unsignedOversizedLengthStdout = String.fromCharCode(unsignedOversizedLengthHeader[0]) +
4141
Buffer.from(unsignedOversizedLengthHeader.subarray(1)).toString('utf-8');
42-
// FF 0F followed by a small, plausible size (8) and 8 payload bytes. Unlike the
42+
function payloadSize(size) {
43+
const buffer = Buffer.alloc(4);
44+
buffer.writeUInt32BE(size);
45+
return buffer;
46+
}
47+
// The v8 header followed by a small, plausible size (8) and 8 payload bytes. Unlike the
4348
// oversized headers above, this passes the size check, but its payload does not
4449
// begin with the inner v8 header a real frame carries, so it is treated as
4550
// stdout instead of reaching the deserializer.
4651
// Regression fixture for https://github.com/nodejs/node/issues/66164
47-
const plausibleSizeFalseHeader = Buffer.from([
48-
0xff, 0x0f, // V8 serializer header magic
49-
0x00, 0x00, 0x00, 0x08, // Payload size of 8 bytes
50-
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, // "ABCDEFGH", not a real payload
52+
const plausibleSizeFalseHeader = Buffer.concat([
53+
headerOnly,
54+
payloadSize(8),
55+
Buffer.from('ABCDEFGH'), // Not a real payload
5156
]);
5257
const plausibleSizeFalseHeaderStdout = String.fromCharCode(plausibleSizeFalseHeader[0]) +
5358
Buffer.from(plausibleSizeFalseHeader.subarray(1)).toString('utf-8');
54-
// FF 0F, a valid size, then the inner v8 header a real frame repeats, followed
59+
// The v8 header, a valid size, then the inner v8 header a real frame repeats, followed
5560
// by a byte that is not a valid serialized value. This passes the inner header
5661
// check and reaches the deserializer, which throws. This is what a genuine
5762
// report-protocol regression looks like, so the parser must let the error
5863
// surface instead of hiding it as stdout.
59-
const headeredCorruptFrame = Buffer.from([
60-
0xff, 0x0f, // Outer v8 serializer header magic
61-
0x00, 0x00, 0x00, 0x03, // Payload size of 3 bytes
62-
0xff, 0x0f, // Inner v8 header that a real frame repeats
63-
0xee, // Not a valid serialized value
64+
const headeredCorruptFrame = Buffer.concat([
65+
headerOnly,
66+
payloadSize(headerLength + 1),
67+
headerOnly,
68+
Buffer.from([0xee]), // Not a valid serialized value
6469
]);
65-
// FF 0F with a declared size of 1, then more header bytes. The payload is
70+
// The v8 header with a declared size of 1, then more header bytes. The payload is
6671
// shorter than the inner v8 header a real frame carries, so it can never be a
6772
// real frame. The length guard must reject it as stdout without reaching the
6873
// deserializer.
69-
const shortPayloadFalseHeader = Buffer.from([
70-
0xff, 0x0f, // Outer v8 serializer header magic
71-
0x00, 0x00, 0x00, 0x01, // Payload size of 1 byte, too short for a header
72-
0xff, 0x0f, // Trailing bytes that also look like a header
74+
const shortPayloadFalseHeader = Buffer.concat([
75+
headerOnly,
76+
payloadSize(1),
77+
headerOnly, // Trailing bytes that also look like a header
7378
]);
7479

7580
function collectStdout(reported) {

0 commit comments

Comments
 (0)