buffer: neuter external `nullptr` buffers · nodejs/node@5667369 · GitHub
Skip to content

Commit 5667369

Browse files
indutnyrvagg
authored andcommitted
buffer: neuter external nullptr buffers
Neuter external `nullptr` buffers, otherwise their contents will be materialized on access, and the buffer instance will be internalized. This leads to a crash like this: v8::ArrayBuffer::Neuter Only externalized ArrayBuffers can be neutered Fix: #3619 PR-URL: #3624 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
1 parent 7d0b589 commit 5667369

4 files changed

Lines changed: 60 additions & 0 deletions

File tree

src/node_buffer.cc

Lines changed: 5 additions & 0 deletions
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <node.h>
2+
#include <node_buffer.h>
3+
#include <util.h>
4+
#include <v8.h>
5+
6+
static int alive;
7+
8+
static void FreeCallback(char* data, void* hint) {
9+
CHECK_EQ(data, nullptr);
10+
alive--;
11+
}
12+
13+
void Run(const v8::FunctionCallbackInfo<v8::Value>& args) {
14+
v8::Isolate* isolate = args.GetIsolate();
15+
alive++;
16+
17+
{
18+
v8::HandleScope scope(isolate);
19+
v8::Local<v8::Object> buf = node::Buffer::New(
20+
isolate,
21+
nullptr,
22+
0,
23+
FreeCallback,
24+
nullptr).ToLocalChecked();
25+
26+
char* data = node::Buffer::Data(buf);
27+
CHECK_EQ(data, nullptr);
28+
}
29+
30+
isolate->RequestGarbageCollectionForTesting(
31+
v8::Isolate::kFullGarbageCollection);
32+
33+
CHECK_EQ(alive, 0);
34+
}
35+
36+
void init(v8::Local<v8::Object> target) {
37+
NODE_SET_METHOD(target, "run", Run);
38+
}
39+
40+
NODE_MODULE(binding, init);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
'targets': [
3+
{
4+
'target_name': 'binding',
5+
'sources': [ 'binding.cc' ]
6+
}
7+
]
8+
}
Lines changed: 7 additions & 0 deletions

0 commit comments

Comments
 (0)