summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2017-11-01 00:37:51 +0100
committerAnna Henningsen <anna@addaleax.net>2017-11-06 17:53:37 +0000
commit0300565af933e705452e35a68b8befbb3afac719 (patch)
tree91f1fcf0b866a24c09d58cb09626b7c03726de9c
parent4de10273bbe7c4772bf142100945ed84dfc5e65d (diff)
downloadandroid-node-v8-0300565af933e705452e35a68b8befbb3afac719.tar.gz
android-node-v8-0300565af933e705452e35a68b8befbb3afac719.tar.bz2
android-node-v8-0300565af933e705452e35a68b8befbb3afac719.zip
zlib: warn before crash on invalid internals usage
PR-URL: https://github.com/nodejs/node/pull/16657 Refs: https://github.com/nodejs/node/issues/16649 Refs: https://github.com/nodejs/node/issues/14161 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net>
-rw-r--r--src/node_zlib.cc10
-rw-r--r--test/abort/test-zlib-invalid-internals-usage.js20
2 files changed, 30 insertions, 0 deletions
diff --git a/src/node_zlib.cc b/src/node_zlib.cc
index 067e8d96a0..01f713afd7 100644
--- a/src/node_zlib.cc
+++ b/src/node_zlib.cc
@@ -422,6 +422,16 @@ class ZCtx : public AsyncWrap {
// just pull the ints out of the args and call the other Init
static void Init(const FunctionCallbackInfo<Value>& args) {
+ // Refs: https://github.com/nodejs/node/issues/16649
+ // Refs: https://github.com/nodejs/node/issues/14161
+ if (args.Length() == 5) {
+ fprintf(stderr,
+ "WARNING: You are likely using a version of node-tar or npm that "
+ "is incompatible with this version of Node.js.\nPlease use "
+ "either the version of npm that is bundled with Node.js, or "
+ "a version of npm (> 5.5.1 or < 5.4.0) or node-tar (> 4.0.1) "
+ "that is compatible with Node.js 9 and above.\n");
+ }
CHECK(args.Length() == 7 &&
"init(windowBits, level, memLevel, strategy, writeResult, writeCallback,"
" dictionary)");
diff --git a/test/abort/test-zlib-invalid-internals-usage.js b/test/abort/test-zlib-invalid-internals-usage.js
new file mode 100644
index 0000000000..c076c7df5e
--- /dev/null
+++ b/test/abort/test-zlib-invalid-internals-usage.js
@@ -0,0 +1,20 @@
+'use strict';
+require('../common');
+const assert = require('assert');
+const os = require('os');
+const cp = require('child_process');
+
+if (process.argv[2] === 'child') {
+ // This is the heart of the test.
+ new (process.binding('zlib').Zlib)(0).init(1, 2, 3, 4, 5);
+} else {
+ const child = cp.spawnSync(`${process.execPath}`, [`${__filename}`, 'child']);
+
+ assert.strictEqual(child.stdout.toString(), '');
+ assert.ok(child.stderr.includes(
+ 'WARNING: You are likely using a version of node-tar or npm that ' +
+ 'is incompatible with this version of Node.js.' + os.EOL +
+ 'Please use either the version of npm that is bundled with Node.js, or ' +
+ 'a version of npm (> 5.5.1 or < 5.4.0) or node-tar (> 4.0.1) that is ' +
+ 'compatible with Node.js 9 and above.' + os.EOL));
+}