-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
workers, 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
Fixes: nodejs#35263 PR-URL: nodejs#35416 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
@addaleax @nodejs/workers ... The following segfaults on master and 14.x ...
I'll be investigating shortly...
lldb yields...
The text was updated successfully, but these errors were encountered: