Skip to content

Commit babeb58

Browse files
amdokuaddaleax
authored andcommitted
src: add aliased-buffer-overflow abort test
Added native extension similar to test/addons/stringbytes-external-exceeded-max. Added an abort test to regression test the non overflow behaviour. PR-URL: nodejs#31740 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 8245a78 commit babeb58

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

test/abort/common.gypi

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
'defines': [ 'V8_DEPRECATION_WARNINGS=1', 'NODE_WANT_INTERNALS=1' ],
3+
'conditions': [
4+
[ 'OS in "linux freebsd openbsd solaris android aix cloudabi"', {
5+
'cflags': ['-Wno-cast-function-type'],
6+
}],
7+
],
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <stdlib.h>
2+
#include <node.h>
3+
#include <v8.h>
4+
5+
#include <aliased_buffer.h>
6+
#include <util-inl.h>
7+
8+
void AllocateAndResizeBuffer(
9+
const v8::FunctionCallbackInfo<v8::Value>& args) {
10+
v8::Isolate* isolate = args.GetIsolate();
11+
int64_t length = args[0].As<v8::BigInt>()->Int64Value();
12+
13+
node::AliasedBigUint64Array array{isolate, 0};
14+
15+
array.reserve(length);
16+
assert(false);
17+
}
18+
19+
void init(v8::Local<v8::Object> exports) {
20+
NODE_SET_METHOD(exports,
21+
"allocateAndResizeBuffer",
22+
AllocateAndResizeBuffer);
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
'targets': [
3+
{
4+
'target_name': 'binding',
5+
'sources': [ 'binding.cc' ],
6+
'includes': ['../common.gypi'],
7+
}
8+
]
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const cp = require('child_process');
5+
6+
// This test ensures that during resizing of an Aliased*Array the computation
7+
// of the new size does not overflow.
8+
9+
if (process.argv[2] === 'child') {
10+
// test
11+
const binding = require(`./build/${common.buildType}/binding`);
12+
13+
const bigValue = BigInt('0xE000 0000 E000 0000');
14+
binding.AllocateAndResizeBuffer(bigValue);
15+
assert.fail('this should be unreachable');
16+
} else {
17+
// observer
18+
const child = cp.spawn(`${process.execPath}`, [`${__filename}`, 'child']);
19+
child.on('exit', common.mustCall(function(code, signal) {
20+
if (common.isWindows) {
21+
assert.strictEqual(code, 134);
22+
assert.strictEqual(signal, null);
23+
} else {
24+
assert.strictEqual(code, null);
25+
assert.strictEqual(signal, 'SIGABRT');
26+
}
27+
}));
28+
}

0 commit comments

Comments
 (0)