Skip to content

child_process: advanced serialization segfaults on a host object with an index property #67767

Backlog

Description

@ketd

Version

v26.13.1 (v24.22.3 crashes the same way; v22.23.5 does not)

Platform

Linux x64 (official node:26.13.1-bookworm-slim image) and macOS arm64 (official v26.13.1 binary)

Subsystem

child_process

What steps will reproduce the bug?

// repro.js
const { fork } = require('node:child_process');
const { MessageChannel } = require('node:worker_threads');
if (process.argv[2] === 'child') return;
const { port1 } = new MessageChannel();
port1[0] = 'x';
fork(__filename, ['child'], { serialization: 'advanced' }).send(port1);
$ node repro.js
Segmentation fault (core dumped)

With a property that is not an index (port1.named = 'x'), the child receives {"named":"x"}.

How often does it reproduce? Is there a required condition?

Always, when the sent value is a host object (here a MessagePort) with an own enumerable index property.

What is the expected behavior? Why is that the expected behavior?

The child receives { '0': 'x' }. The C++ code is documented to send the same shallow copy as writeValue({ ...object }) in serialization.js. A JS error would also be acceptable, but not a crash.

What do you see instead?

Segmentation fault (exit code 139).

Additional information

SerializerDelegate::WriteHostObject in src/node_ipc_serdes.cc (the non-view branch) calls object->GetOwnPropertyNames(context). Its default KeyConversionMode is kKeepNumbers, so index keys come back as Smis. The loop then calls copy->CreateDataProperty(context, key.As<Name>(), val). As<Name>() is an unchecked cast, and V8 dereferences the Smi as a Name.

Requesting string keys fixes it: object->GetOwnPropertyNames(context, static_cast<PropertyFilter>(ONLY_ENUMERABLE | SKIP_SYMBOLS), KeyConversionMode::kConvertToString). Another option is to branch on key->IsUint32() and use the CreateDataProperty(context, uint32_t, value) overload.

The code is the same on main (be0f17c).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions