summaryrefslogtreecommitdiff
path: root/test/parallel/test-zlib-object-write.js
diff options
context:
space:
mode:
authorKevin Locke <kevin@kevinlocke.name>2017-11-12 00:30:34 -0700
committerAnna Henningsen <anna@addaleax.net>2017-11-18 20:55:57 +0100
commit662d803682a279508ff2f4434be50f5e268c260d (patch)
tree6ca28756dda3ebf66183345dd3d629d0d32fad3e /test/parallel/test-zlib-object-write.js
parent6c5a39c51f82ea7c2f82e3faaa505c0dc3388647 (diff)
downloadandroid-node-v8-662d803682a279508ff2f4434be50f5e268c260d.tar.gz
android-node-v8-662d803682a279508ff2f4434be50f5e268c260d.tar.bz2
android-node-v8-662d803682a279508ff2f4434be50f5e268c260d.zip
zlib: fix assert fail for bad write in object mode
add4b0ab8c 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 <kevin@kevinlocke.name> PR-URL: https://github.com/nodejs/node/pull/16960 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'test/parallel/test-zlib-object-write.js')
-rw-r--r--test/parallel/test-zlib-object-write.js11
1 files changed, 11 insertions, 0 deletions
diff --git a/test/parallel/test-zlib-object-write.js b/test/parallel/test-zlib-object-write.js
new file mode 100644
index 0000000000..98f34b38be
--- /dev/null
+++ b/test/parallel/test-zlib-object-write.js
@@ -0,0 +1,11 @@
+'use strict';
+
+require('../common');
+const assert = require('assert');
+const { Gunzip } = require('zlib');
+
+const gunzip = new Gunzip({ objectMode: true });
+assert.throws(
+ () => gunzip.write({}),
+ TypeError
+);