From d1941fca1f522c861b1fa6ba5df11f5c087e213c Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Sat, 5 Jul 2025 17:09:21 +0100 Subject: [PATCH] src: check import attributes value types as strings --- src/module_wrap.cc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/module_wrap.cc b/src/module_wrap.cc index 3d27b878fd2220..83728032406645 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -63,6 +63,10 @@ using v8::UnboundModuleScript; using v8::Undefined; using v8::Value; +inline bool DataIsString(Local data) { + return data->IsValue() && data.As()->IsString(); +} + void ModuleCacheKey::MemoryInfo(MemoryTracker* tracker) const { tracker->TrackField("specifier", specifier); tracker->TrackField("import_attributes", import_attributes); @@ -83,6 +87,9 @@ ModuleCacheKey ModuleCacheKey::From(Local context, for (int i = 0; i < import_attributes->Length(); i += elements_per_attribute) { + DCHECK(DataIsString(import_attributes->Get(context, i))); + DCHECK(DataIsString(import_attributes->Get(context, i + 1))); + Local v8_key = import_attributes->Get(context, i).As(); Local v8_value = import_attributes->Get(context, i + 1).As(); @@ -488,9 +495,14 @@ static Local createImportAttributesContainer( LocalVector values(isolate, num_attributes); for (int i = 0; i < raw_attributes->Length(); i += elements_per_attribute) { + Local key = raw_attributes->Get(realm->context(), i); + Local value = raw_attributes->Get(realm->context(), i + 1); + DCHECK(DataIsString(key)); + DCHECK(DataIsString(value)); + int idx = i / elements_per_attribute; - names[idx] = raw_attributes->Get(realm->context(), i).As(); - values[idx] = raw_attributes->Get(realm->context(), i + 1).As(); + names[idx] = key.As(); + values[idx] = value.As(); } Local attributes = Object::New( @@ -507,6 +519,7 @@ static Local createModuleRequestsContainer( LocalVector requests(isolate, raw_requests->Length()); for (int i = 0; i < raw_requests->Length(); i++) { + DCHECK(raw_requests->Get(context, i)->IsModuleRequest()); Local module_request = raw_requests->Get(realm->context(), i).As();