Skip to content

Commit 45ca714

Browse files
kevinoidMylesBorins
authored andcommitted
zlib: fix assert fail for bad write in object mode
add4b0a introduced a regression from Node 8 to Node 9 by removing the `ArrayBuffer.isView(chunk)` check in `Zlib.prototype._transform` without properly forcing `opts.objectMode` to `false` in the constructor because the change to `opts` occurs after `opts` has been passed to the `Transform` constructor. This commit fixes the issue by moving the call to `Transform` after the changes to `opts`. The regression can be demonstrated by running node -e 'require("zlib").Gunzip({objectMode: true}).write({})' On Node 8 this correctly throws a `TypeError`: events.js:183 throw er; // Unhandled 'error' event ^ TypeError: invalid input at Gunzip._transform (zlib.js:367:15) at Gunzip.Transform._read (_stream_transform.js:186:10) at Gunzip.Transform._write (_stream_transform.js:174:12) at doWrite (_stream_writable.js:387:12) at writeOrBuffer (_stream_writable.js:373:5) at Gunzip.Writable.write (_stream_writable.js:290:11) at [eval]:1:44 at ContextifyScript.Script.runInThisContext (vm.js:50:33) at Object.runInThisContext (vm.js:139:38) at Object.<anonymous> ([eval]-wrapper:6:22) On Node 9 this causes an assertion failure: node[21732]: ../src/node_zlib.cc:179:static void node::{anonymous}::ZCtx::Write(const v8::FunctionCallbackInfo<v8::Value>&) [with bool async = true]: Assertion `Buffer::HasInstance(args[1])' failed. 1: node::Abort() [node] 2: node::Assert(char const* const (*) [4]) [node] 3: 0x1250916 [node] 4: v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionCallbackInfo<v8::Value> const&)) [node] 5: 0xb7547c [node] 6: v8::internal::Builtin_HandleApiCall(int, v8::internal::Object**, v8::internal::Isolate*) [node] 7: 0x20c44b8842fd Aborted Signed-off-by: Kevin Locke <[email protected]> PR-URL: #16960 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 9a4abe4 commit 45ca714

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/zlib.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ function flushCallback(level, strategy, callback) {
154154
// true or false if there is anything in the queue when
155155
// you call the .write() method.
156156
function Zlib(opts, mode) {
157-
Transform.call(this, opts);
158157
var chunkSize = Z_DEFAULT_CHUNK;
159158
var flush = Z_NO_FLUSH;
160159
var finishFlush = Z_FINISH;
@@ -259,6 +258,7 @@ function Zlib(opts, mode) {
259258
opts.writableObjectMode = false;
260259
}
261260
}
261+
Transform.call(this, opts);
262262
this.bytesRead = 0;
263263
this._handle = new binding.Zlib(mode);
264264
this._handle.jsref = this; // Used by processCallback() and zlibOnError()
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
require('../common');
4+
const assert = require('assert');
5+
const { Gunzip } = require('zlib');
6+
7+
const gunzip = new Gunzip({ objectMode: true });
8+
assert.throws(
9+
() => gunzip.write({}),
10+
TypeError
11+
);

0 commit comments

Comments
 (0)