Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Fix getCommandValues and sandbox crashes (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
chase authored Nov 29, 2023
2 parents 2066f10 + f164018 commit b0f14a2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/electron/ELECTRON_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.3.0-rc9
20.3.0-rc10
30 changes: 23 additions & 7 deletions src/electron/office/document_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -785,13 +785,29 @@ v8::Local<v8::Promise> DocumentClient::GetCommandValues(
if (!result) {
return promise.Resolve();
}
v8::Local<v8::String> res_json_str;
if (!v8::String::NewFromUtf8(promise.isolate(), result.get())
.ToLocal(&res_json_str)) {
return promise.Resolve();
}
promise.Resolve(v8::JSON::Parse(promise.GetContext(), res_json_str)
.FromMaybe(v8::Local<v8::Value>()));
promise.task_runner()->PostTask(
FROM_HERE,
base::BindOnce(
[](Promise<v8::Value> promise, LokStrPtr result,
base::WeakPtr<OfficeClient> office) {
if (!office.MaybeValid())
return;
v8::Isolate* isolate = promise.isolate();
v8::HandleScope handle_scope(isolate);
v8::MicrotasksScope microtasks_scope(
isolate, v8::MicrotasksScope::kDoNotRunMicrotasks);
v8::Context::Scope context_scope(promise.GetContext());

v8::Local<v8::String> res_json_str;
if (!v8::String::NewFromUtf8(promise.isolate(), result.get())
.ToLocal(&res_json_str)) {
return promise.Resolve();
}
promise.Resolve(
v8::JSON::Parse(promise.GetContext(), res_json_str)
.FromMaybe(v8::Local<v8::Value>()));
},
std::move(promise), std::move(result), std::move(office)));
},
std::move(promise), command, OfficeClient::GetWeakPtr()));

Expand Down
1 change: 1 addition & 0 deletions src/electron/office/office_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ bool OfficeInstance::IsValid() {
}

void OfficeInstance::Unset() {
if (!Get()) return;
Get()->unset_ = true;
Get()->instance_.reset();
}
Expand Down
3 changes: 1 addition & 2 deletions src/electron/shell/renderer/renderer_client_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,7 @@ void RendererClientBase::RenderThreadStarted() {

#if BUILDFLAG(ENABLE_OFFICE)
// we only start LO in non-sandboxed processes
if (!command_line->HasSwitch(switches::kEnableSandbox) ||
command_line->HasSwitch(sandbox::policy::switches::kNoSandbox)) {
if (command_line->HasSwitch(sandbox::policy::switches::kNoSandbox)) {
office::OfficeInstance::Create();
}
#endif
Expand Down

0 comments on commit b0f14a2

Please sign in to comment.