electron: [Bug]: crash of a window, renderer process cause of memory cage and asar
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for a bug report that matches the one I want to file, without success.
Electron Version
22.0.x
What operating system are you using?
Windows
Operating System Version
Windows 7, 10, 11
What arch are you using?
x64
Last Known Working Electron version
20.x
Expected Behavior
no crash
Actual Behavior
It actually crashes in:
cpp-marking-state-inl.h
void CppMarkingState::MarkAndPush(const EmbedderDataSlot type_slot,
const EmbedderDataSlot instance_slot) {
LocalEmbedderHeapTracer::WrapperInfo info;
>>>> if (LocalEmbedderHeapTracer::ExtractWrappableInfo(
isolate_, wrapper_descriptor_, type_slot, instance_slot, &info)) {
marking_state_.MarkAndPush(
cppgc::internal::HeapObjectHeader::FromObject(info.second));```
with exception code: 0xc0000005
At first glace this seems to be coming from a native module which does not work with the new caging system, but i removed all native modules and it still crashed. I figured that it does not happen when running locally through npm/yarn starts but after building to a package it does.
After looking a bit more careful at the stack trace i found that the calls originate from
::Archive::New(const v8::FunctionCallbackInfo<v8::Value> & args) Line 63
C:\projects\src\electron\shell\common\api\electron_api_asar.cc (63)
auto* archive_wrap = new Archive(std::move(archive));
archive_wrap->Wrap(args.This());
If the origin is asar this would explain that it only crashes after build and not on locally runs started with npm.
I debugged with 22.0.3 (but happens with any 22.0.x) which happens to be chrome: 108.0.5359.179 which has v8 version 10.8.168.25
Testcase Gist URL
No response
Additional Information
This crashes also on linux (kernel 6.1, x64 arch)
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 21 (3 by maintainers)
I believe this is a bug in v8, exposed recently in v22 since the v8 sandbox is enabled by default for x64/arm64 (https://chromium.googlesource.com/v8/v8.git/+/a8c27fcc9f9f15a0110a409190a2b514ec86e37f).
This seems to be caused by an out-of-bounds embedder slot index, as pinpointed by the DCHECK failure above:
There’s several frames here inlined, seemingly even in the debug build, so the full call stack is really:
Rough reproduce steps:
--log-level=0and--trace-warningsflagsAnalysis:
DCHECK asserts from a lack of a field at index 1, where it’s expecting an instance field. The embedder field count in this case is 1, and it needs to be at least 2.
There is an existing check on the embedder field count in
src/heap/embedder-tracing-inl.hin another overload toLocalEmbedderHeapTracer::ExtractWrappableInfo: https://chromium.googlesource.com/v8/v8.git/+/refs/heads/10.8.169/src/heap/embedder-tracing-inl.h#19In the original change that check also protected the
EmbedderDataSlotctor that looked up the indexes forwrapper_descriptor.wrappable_type_index(0) andwrapper_descriptor.wrappable_instance_index(1): https://chromium.googlesource.com/v8/v8.git/+/d10f61e1/src/heap/embedder-tracing-inl.h#19However a later refactoring moved the
EmbedderDataSlotout into a separate overloaded function (https://chromium-review.googlesource.com/c/v8/v8/+/3386600): https://chromium.googlesource.com/v8/v8.git/+/804aaa5c6^!/src/heap/embedder-tracing-inl.hIn the same change the
LocalEmbedderHeapTracer::EmbedderWriteBarrierwas updated to lookup thetype_slotandinstance_slotindices: https://chromium-review.googlesource.com/c/v8/v8/+/3386600/14/src/heap/embedder-tracing.cc From the call stack above though this path isn’t protected by the original count check.I believe this may not be observed in non-sandbox builds because of the point where it later attempts to actually convert the embedded data slot as a pointer in
EmbedderDataSlot::ToAlignedPointer: https://chromium.googlesource.com/v8/v8.git/+/refs/heads/10.8.169/src/objects/embedder-data-slot-inl.h#91 This is called fromLocalEmbedderHeapTracer::ExtractWrappableInfo, in release builds this path is reached: https://chromium.googlesource.com/v8/v8.git/+/refs/heads/10.8.169/src/heap/embedder-tracing-inl.h#33The fix here seems to be to add a similar count check in
LocalEmbedderHeapTracer::EmbedderWriteBarrierprior to theEmbedderDataSlotconstructionsrc/heap/embedder-tracing.cc:Note 1: The root cause is unclear to me how the embedder field count can be become different from the assumed fields for the type and instance. It’s also unclear why the Electron asar path exhibits this issue, I’m not familiar enough with the v8 project to really dig in here. However, since they already have a field count check it seems like there were some expected cases where it might have mismatched.
Note 2: As far as future v8 releases, they recently removed the local embedder code in favor of cppgc: https://chromium-review.googlesource.com/c/v8/v8/+/4174081 Unsure if the current cppgc logic is affected: https://chromium.googlesource.com/v8/v8.git/+/fd6efc347d78ff/src/heap/cppgc-js/cpp-heap.cc#785
I’ve opened a v8 issue here to get their input: https://bugs.chromium.org/p/v8/issues/detail?id=13777