Skip to content

Commit 0f3e3e5

Browse files
committed
zlib: warn before crash on invalid internals usage
Refs: nodejs#16649 Refs: nodejs#14161
1 parent 7489ee8 commit 0f3e3e5

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/node_zlib.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,16 @@ class ZCtx : public AsyncWrap {
422422

423423
// just pull the ints out of the args and call the other Init
424424
static void Init(const FunctionCallbackInfo<Value>& args) {
425+
// Refs: https://github.com/nodejs/node/issues/16649
426+
// Refs: https://github.com/nodejs/node/issues/14161
427+
if (args.Length() == 5) {
428+
fprintf(stderr,
429+
"WARNING: You are likely using a version of node-tar or npm that "
430+
"uses the internals of Node.js in an invalid way.\nPlease use "
431+
"either the version of npm that is bundled with Node.js, or "
432+
"a version of npm (> 5.5.1 or < 5.4.0) or node-tar (> 4.0.1) "
433+
"that is compatible with Node 9 and above.\n");
434+
}
425435
CHECK(args.Length() == 7 &&
426436
"init(windowBits, level, memLevel, strategy, writeResult, writeCallback,"
427437
" dictionary)");
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const cp = require('child_process');
5+
6+
if (process.argv[2] === 'child') {
7+
// This is the heart of the test.
8+
new (process.binding('zlib').Zlib)(0).init(1, 2, 3, 4, 5);
9+
} else {
10+
const child = cp.spawnSync(`${process.execPath}`, [`${__filename}`, 'child']);
11+
const stderr = child.stderr.toString();
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 uses ' +
16+
'the internals of Node.js in an invalid way.\n' +
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 9 and above.\n'));
20+
}

0 commit comments

Comments
 (0)