Skip to content

Commit 356441a

Browse files
committed
src: add length assertion in ABVC nullptr case
When ABVC receives a view on an array buffer with a null data pointer, it sets its own data pointer to uninitialized stack memory. While V8 _should_ always have the view length set to zero in this case, it's worth double-checking. Refs: nodejs#62343
1 parent 7afc299 commit 356441a

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/util-inl.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,12 @@ void ArrayBufferViewContents<T, S>::Read(v8::Local<v8::ArrayBufferView> abv) {
593593
if (length_ > sizeof(stack_storage_) || abv->HasBuffer()) {
594594
v8::Local<v8::ArrayBuffer> ab = abv->Buffer();
595595
void* ab_data = ab->Data();
596-
data_ = ab_data != nullptr ? static_cast<T*>(ab_data) + abv->ByteOffset()
597-
: stack_storage_;
596+
if (ab_data != nullptr) {
597+
data_ = static_cast<T*>(ab_data) + abv->ByteOffset();
598+
} else {
599+
CHECK_EQ(length_, 0);
600+
data_ = stack_storage_;
601+
}
598602
was_detached_ = ab->WasDetached();
599603
} else {
600604
abv->CopyContents(stack_storage_, sizeof(stack_storage_));

0 commit comments

Comments
 (0)