Commit e4c3791b authored by Kai Ninomiya's avatar Kai Ninomiya Committed by Commit Bot

Fix std::string use-after-frees in GPUShaderModule::Create

Bug: None
Change-Id: I6a9f7a2bda46e786a3137a6a8e9a84948a301678
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2337102
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
Auto-Submit: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: default avatarAustin Eng <enga@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794767}
parent 2fa1d350
...@@ -21,13 +21,14 @@ GPUShaderModule* GPUShaderModule::Create( ...@@ -21,13 +21,14 @@ GPUShaderModule* GPUShaderModule::Create(
WGPUShaderModuleDescriptor dawn_desc = {}; WGPUShaderModuleDescriptor dawn_desc = {};
WGPUShaderModuleWGSLDescriptor wgsl_desc = {}; WGPUShaderModuleWGSLDescriptor wgsl_desc = {};
WGPUShaderModuleSPIRVDescriptor spirv_desc = {}; WGPUShaderModuleSPIRVDescriptor spirv_desc = {};
std::string wgsl_code;
auto wgsl_or_spirv = webgpu_desc->code(); auto wgsl_or_spirv = webgpu_desc->code();
if (wgsl_or_spirv.IsUSVString()) { if (wgsl_or_spirv.IsUSVString()) {
std::string code = wgsl_or_spirv.GetAsUSVString().Utf8(); wgsl_code = wgsl_or_spirv.GetAsUSVString().Utf8();
wgsl_desc.chain.sType = WGPUSType_ShaderModuleWGSLDescriptor; wgsl_desc.chain.sType = WGPUSType_ShaderModuleWGSLDescriptor;
wgsl_desc.source = code.c_str(); wgsl_desc.source = wgsl_code.c_str();
dawn_desc.nextInChain = reinterpret_cast<WGPUChainedStruct*>(&wgsl_desc); dawn_desc.nextInChain = reinterpret_cast<WGPUChainedStruct*>(&wgsl_desc);
} else { } else {
DCHECK(wgsl_or_spirv.IsUint32Array()); DCHECK(wgsl_or_spirv.IsUint32Array());
...@@ -48,8 +49,10 @@ GPUShaderModule* GPUShaderModule::Create( ...@@ -48,8 +49,10 @@ GPUShaderModule* GPUShaderModule::Create(
dawn_desc.nextInChain = reinterpret_cast<WGPUChainedStruct*>(&spirv_desc); dawn_desc.nextInChain = reinterpret_cast<WGPUChainedStruct*>(&spirv_desc);
} }
std::string label;
if (webgpu_desc->hasLabel()) { if (webgpu_desc->hasLabel()) {
dawn_desc.label = webgpu_desc->label().Utf8().data(); label = webgpu_desc->label().Utf8();
dawn_desc.label = label.c_str();
} }
return MakeGarbageCollected<GPUShaderModule>( return MakeGarbageCollected<GPUShaderModule>(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment