Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: Check for overflow when resizing AliasedBufferBase #31740

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
amdoku committed Feb 17, 2020
commit 2f23066a01fe9dba5ea8b787e4c76625e193d7e8
8 changes: 8 additions & 0 deletions test/abort/common.gypi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
'defines': [ 'V8_DEPRECATION_WARNINGS=1', 'NODE_WANT_INTERNALS=1' ],
'conditions': [
[ 'OS in "linux freebsd openbsd solaris android aix cloudabi"', {
'cflags': ['-Wno-cast-function-type'],
}],
],
}
23 changes: 23 additions & 0 deletions test/abort/test_abort-aliased-buffer-overflow/binding.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <stdlib.h>
#include <node.h>
#include <v8.h>

#include <aliased_buffer.h>
#include <util-inl.h>

void AllocateAndResizeBuffer(
const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
int64_t length = args[0].As<v8::BigInt>()->Int64Value();

node::AliasedBigUint64Array array{isolate, 0};

array.reserve(length);
assert(false);
}

void init(v8::Local<v8::Object> exports) {
NODE_SET_METHOD(exports,
"allocateAndResizeBuffer",
AllocateAndResizeBuffer);
}
9 changes: 9 additions & 0 deletions test/abort/test_abort-aliased-buffer-overflow/binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
'targets': [
{
'target_name': 'binding',
'sources': [ 'binding.cc' ],
'includes': ['../common.gypi'],
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const cp = require('child_process');

// This test ensures that during resizing of an Aliased*Array the computation
// of the new size does not overflow.

if (process.argv[2] === 'child') {
// test
const binding = require(`./build/${common.buildType}/binding`);

const bigValue = BigInt('0xE000 0000 E000 0000');
binding.AllocateAndResizeBuffer(bigValue);
assert.fail('this should be unreachable');
} else {
// observer
const child = cp.spawn(`${process.execPath}`, [`${__filename}`, 'child']);
child.on('exit', common.mustCall(function(code, signal) {
if (common.isWindows) {
assert.strictEqual(code, 134);
assert.strictEqual(signal, null);
} else {
assert.strictEqual(code, null);
assert.strictEqual(signal, 'SIGABRT');
}
}));
}