nodejs / nodejs/nan

Weird and inexplicable crashes when using TypedArrayContents

Open
#922 26 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
3.4k
Forks
531
Avg merge
21m
Merged PRs (30d)
1

Description

I'm getting really weird crashes with v8 array buffers / typed arrays

Base:

size_t numEntries = 2 * TOTAL_NUM_BANDS;
size_t numBytes = sizeof(float) * numEntries;
v8::Local<v8::ArrayBuffer> dataBuffer = v8::ArrayBuffer::New(v8::Isolate::GetCurrent(), numBytes);
v8::Local<v8::Float32Array> dataArr = v8::Float32Array::New(minMaxDataBuffer, 0, numEntries);

works:

 auto dataPtr = static_cast<float*>(dataBuffer->GetContents().Data());

segfaults:

auto test = Nan::TypedArrayContents<float>(dataArr);

...but it doesn't segfault immediately, but rather a couple of seconds later, probably when some GC happens.

I don't even need to do anything with the pointer. It is enough to construct a (temporary) Nan::TypedArrayContents

I have digged through the nan_typedarray_contents.h header

once I comment out

data = static_cast<char*>(buffer->GetBackingStore()->Data()) + byte_offset;

there is no crash.

I tried to find out what this is, but now it's getting really weird:

auto dataPtr2 = static_cast<float*>(dataBuffer->GetBackingStore()->Data());
//auto dataPtr3 = static_cast<float*>(dataBuffer->GetBackingStore()->Data());

works.
Where as

auto dataPtr2 = static_cast<float*>(dataBuffer->GetBackingStore()->Data());
auto dataPtr3 = static_cast<float*>(dataBuffer->GetBackingStore()->Data());

(just the first call repeated)
segfaults immediately... I suppose this is a node bug?

I'm compiling against electron 8.0.0, node version should be 12.13.0

I'll try with a later node / electron version now

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with nan_typedarray_contents.h and the reported TypedArrayContents construction, then reproduce the crash using Electron 8.0.0 with Node 12.13.0 and the provided ArrayBuffer/Float32Array code. Compare the GetContents and GetBackingStore paths while observing the delayed and immediate failures around garbage collection. Done means the reproduction no longer crashes or the issue is narrowed to a confirmed upstream component with a focused test or report.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, electron, nodejs
Domain
backend, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.