From d6a0ffe367ad784182a945c0014abce36ea9b6b7 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 1 Nov 2017 00:37:51 +0100 Subject: [PATCH] zlib: warn before crash on invalid internals usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Refael Ackermann Reviewed-By: Myles Borins Reviewed-By: Tobias Nießen Reviewed-By: Daijiro Wachi Reviewed-By: Joyee Cheung Reviewed-By: Ben Noordhuis Reviewed-By: Anna Henningsen --- src/node_zlib.cc | 10 ++++++++++ .../test-zlib-invalid-internals-usage.js | 20 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 test/abort/test-zlib-invalid-internals-usage.js diff --git a/src/node_zlib.cc b/src/node_zlib.cc index 93583181608132..221009f80e0a82 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -425,6 +425,16 @@ class ZCtx : public AsyncWrap { // just pull the ints out of the args and call the other Init static void Init(const FunctionCallbackInfo& 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 00000000000000..c076c7df5e4410 --- /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)); +}