Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upworkers, crypto: passing KeyObject as workerData crashes #35263
Comments
|
Ok... yeah, it's what I suspected... I added a CHECK to verify in my local branch:
|
|
We could probably make |
|
I’ve marked this |
|
I was going to work up the fix this next week as part of #35093 but if someone wants to pick it up, feel free! |
|
@addaleax @jasnell I want to pick it up. As a starter how much c++ should i know be knowing to tackle this issue? Edit: I am going through the relevant details from https://github.com/nodejs/node/blob/master/src/README.md and i will try to work on it. Thanks |
|
@ThakurKarthik I don’t think it requires a deep knowledge of the language, but some basic understanding would be helpful. Fwiw, the relevant parts of the code base are: Lines 3268 to 3288 in a8971f8 Lines 6953 to 6954 in a8971f8 And this is how we’ve solved this for the Lines 1076 to 1094 in a8971f8 |
|
Thanks @addaleax for the pointers |
|
Hi @addaleax with your reference I made these changes and ran
diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index 05da3af09c..8ef2adebeb 100644
--- a/src/node_crypto.cc
+++ b/src/node_crypto.cc
@@ -3265,8 +3265,11 @@ size_t KeyObjectData::GetSymmetricKeySize() const {
return symmetric_key_len_;
}
-Local<Function> KeyObjectHandle::Initialize(Environment* env,
- Local<Object> target) {
+Local<Function> KeyObjectHandle::Initialize(Environment* env) {
+ Local<Function> templ = env->crypto_key_object_handle_constructor();
+ if (!templ.IsEmpty()) {
+ return templ;
+ }
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
t->InstanceTemplate()->SetInternalFieldCount(
KeyObjectHandle::kInternalFieldCount);
@@ -3280,20 +3283,16 @@ Local<Function> KeyObjectHandle::Initialize(Environment* env,
env->SetProtoMethod(t, "export", Export);
auto function = t->GetFunction(env->context()).ToLocalChecked();
- target->Set(env->context(),
- FIXED_ONE_BYTE_STRING(env->isolate(), "KeyObjectHandle"),
- function).Check();
-
- return function;
+ env->set_crypto_key_object_handle_constructor(function);
+ return KeyObjectHandle::Initialize(env);
}
MaybeLocal<Object> KeyObjectHandle::Create(
Environment* env,
std::shared_ptr<KeyObjectData> data) {
Local<Object> obj;
- if (!env->crypto_key_object_handle_constructor()
- ->NewInstance(env->context(), 0, nullptr)
- .ToLocal(&obj)) {
+ Local<Function> fctun = KeyObjectHandle::Initialize(env);
+ if (!fctun->NewInstance(env->context(), 0, nullptr).ToLocal(&obj)) {
return MaybeLocal<Object>();
}
@@ -6950,8 +6949,9 @@ void Initialize(Local<Object> target,
Environment* env = Environment::GetCurrent(context);
SecureContext::Initialize(env, target);
- env->set_crypto_key_object_handle_constructor(
- KeyObjectHandle::Initialize(env, target));
+ target->Set(env->context(),
+ FIXED_ONE_BYTE_STRING(env->isolate(), "KeyObjectHandle"),
+ KeyObjectHandle::Initialize(env)).Check();
env->SetMethod(target, "createNativeKeyObjectClass",
CreateNativeKeyObjectClass);
CipherBase::Initialize(env, target);
diff --git a/src/node_crypto.h b/src/node_crypto.h
index 63468e4f18..8f78103560 100644
--- a/src/node_crypto.h
+++ b/src/node_crypto.h
@@ -447,8 +447,7 @@ class KeyObjectData {
class KeyObjectHandle : public BaseObject {
public:
- static v8::Local<v8::Function> Initialize(Environment* env,
- v8::Local<v8::Object> target);
+ static v8::Local<v8::Function> Initialize(Environment* env);
static v8::MaybeLocal<v8::Object> Create(Environment* env,
std::shared_ptr<KeyObjectData> data);For some reason i am not able to generate the debug build.
Can you guide me how to proceed further ? |
It’s hard to tell without further information, but the only reason that I know of why this might not work is that debug builds take up a lot more memory and disk space. In this case, using |
|
Hi @addaleax I was able to generate the debug build with |
|
@ThakurKarthik Oh, right, that’s … unfortunate, sorry
That’s probably the best approach here – the function is called from |
…eyObjectClass Fixes: nodejs#35263
ThakurKarthik
linked a pull request that will
close
this issue
…eyObjectClass Fixes: nodejs#35263



@addaleax @nodejs/workers ... The following segfaults on master and 14.x ...
I'll be investigating shortly...
lldb yields...