Skip to content

Commit d6a0ffe

Browse files
addaleaxMylesBorins
authored andcommitted
zlib: warn before crash on invalid internals usage
PR-URL: #16657 Refs: #16649 Refs: #14161 Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent ed0fbd8 commit d6a0ffe

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/node_zlib.cc

+10
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,16 @@ class ZCtx : public AsyncWrap {
425425

426426
// just pull the ints out of the args and call the other Init
427427
static void Init(const FunctionCallbackInfo<Value>& args) {
428+
// Refs: https://github.com/nodejs/node/issues/16649
429+
// Refs: https://github.com/nodejs/node/issues/14161
430+
if (args.Length() == 5) {
431+
fprintf(stderr,
432+
"WARNING: You are likely using a version of node-tar or npm that "
433+
"is incompatible with this version of Node.js.\nPlease use "
434+
"either the version of npm that is bundled with Node.js, or "
435+
"a version of npm (> 5.5.1 or < 5.4.0) or node-tar (> 4.0.1) "
436+
"that is compatible with Node.js 9 and above.\n");
437+
}
428438
CHECK(args.Length() == 7 &&
429439
"init(windowBits, level, memLevel, strategy, writeResult, writeCallback,"
430440
" dictionary)");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
require('../common');
3+
const assert = require('assert');
4+
const os = require('os');
5+
const cp = require('child_process');
6+
7+
if (process.argv[2] === 'child') {
8+
// This is the heart of the test.
9+
new (process.binding('zlib').Zlib)(0).init(1, 2, 3, 4, 5);
10+
} else {
11+
const child = cp.spawnSync(`${process.execPath}`, [`${__filename}`, 'child']);
12+
13+
assert.strictEqual(child.stdout.toString(), '');
14+
assert.ok(child.stderr.includes(
15+
'WARNING: You are likely using a version of node-tar or npm that ' +
16+
'is incompatible with this version of Node.js.' + os.EOL +
17+
'Please use either the version of npm that is bundled with Node.js, or ' +
18+
'a version of npm (> 5.5.1 or < 5.4.0) or node-tar (> 4.0.1) that is ' +
19+
'compatible with Node.js 9 and above.' + os.EOL));
20+
}

0 commit comments

Comments
 (0)