44#include " node_buffer.h"
55#include " node_platform.h"
66#include " node_file.h"
7+ #include " node_context_data.h"
78#include " node_worker.h"
89#include " tracing/agent.h"
910
@@ -28,6 +29,10 @@ using v8::Symbol;
2829using v8::Value;
2930using worker::Worker;
3031
32+ int const Environment::kNodeContextTag = 0x6e6f64 ;
33+ void * Environment::kNodeContextTagPtr = const_cast <void *>(
34+ static_cast <const void *>(&Environment::kNodeContextTag ));
35+
3136IsolateData::IsolateData (Isolate* isolate,
3237 uv_loop_t * event_loop,
3338 MultiIsolatePlatform* platform,
@@ -430,7 +435,20 @@ bool Environment::RemovePromiseHook(promise_hook_func fn, void* arg) {
430435void Environment::EnvPromiseHook (v8::PromiseHookType type,
431436 v8::Local<v8::Promise> promise,
432437 v8::Local<v8::Value> parent) {
433- Environment* env = Environment::GetCurrent (promise->CreationContext ());
438+ Local<v8::Context> context = promise->CreationContext ();
439+
440+ // Grow the embedder data if necessary to make sure we are not out of bounds
441+ // when reading the magic number.
442+ context->SetAlignedPointerInEmbedderData (
443+ ContextEmbedderIndex::kContextTagBoundary , nullptr );
444+ int * magicNumberPtr = reinterpret_cast <int *>(
445+ context->GetAlignedPointerFromEmbedderData (
446+ ContextEmbedderIndex::kContextTag ));
447+ if (magicNumberPtr != Environment::kNodeContextTagPtr ) {
448+ return ;
449+ }
450+
451+ Environment* env = Environment::GetCurrent (context);
434452 for (const PromiseHookCallback& hook : env->promise_hooks_ ) {
435453 hook.cb_ (type, promise, parent, hook.arg_ );
436454 }
0 commit comments