nan: Weird and inexplicable crashes when using TypedArrayContents
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
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 26 (4 by maintainers)
Right – to be clear, there’s also nothing wrong with NAN here. It’s Node.js that does more or less promise to expose a stable ABI through its module version number, and fails to do so here.
This is for sure a previously unknown issue and should be noted among the known issues. NAN, being a header-only library, has never promised a stable ABI. node-addon-api was created in order to provide a stable ABI.
On November 23, 2021 12:55:09 PM GMT+02:00, Robin Christ @.***> wrote: