Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node crashes if undefined passed to an objectMode readable stream #13753

Closed
75lb opened this issue Jun 17, 2017 · 2 comments
Closed

node crashes if undefined passed to an objectMode readable stream #13753

75lb opened this issue Jun 17, 2017 · 2 comments
Labels
confirmed-bug Issues with confirmed bugs. stream Issues and PRs related to the stream subsystem.

Comments

@75lb
Copy link

75lb commented Jun 17, 2017

  • Version: v8.1.2
  • Platform: Darwin mbp.local 16.6.0 Darwin Kernel Version 16.6.0: Fri Apr 14 16:21:16 PDT 2017; root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64
  • Subsystem: Stream

The following code works on node v7 but crashes on v8:

const Transform = require('stream').Transform
const stream = new Transform({ objectMode: true })

function processChunk (chunk) { return undefined }

stream._transform = function (chunk, enc, done) {
  if (chunk) {
    this.push(processChunk(chunk))
  }
  done()
}

stream.end({ something: 'whatever' })

Node crashes if my processChunk function returns undefined (which it always does for the purpose of this test case), any other value works fine. However, the docs say that "For object mode streams, chunk may be any JavaScript value." If this is true, undefined should work fine, no?

@75lb
Copy link
Author

75lb commented Jun 17, 2017

this is error when running the above script on node v8.1.2:

$ node tmp/issue.js
_stream_readable.js:218
          Object.getPrototypeOf(chunk) !== Buffer.prototype &&
                 ^

TypeError: Cannot convert undefined or null to object
    at Function.getPrototypeOf (<anonymous>)
    at readableAddChunk (_stream_readable.js:218:18)
    at Transform.Readable.push (_stream_readable.js:197:10)
    at Transform.push (_stream_transform.js:151:32)
    at Transform.stream._transform (/Users/lloydb/Documents/tmp/issue.js:8:10)
    at Transform._read (_stream_transform.js:190:10)
    at Transform._write (_stream_transform.js:178:12)
    at doWrite (_stream_writable.js:371:12)
    at writeOrBuffer (_stream_writable.js:357:5)
    at Transform.Writable.write (_stream_writable.js:274:11)

@gibfahn gibfahn added the stream Issues and PRs related to the stream subsystem. label Jun 17, 2017
@gibfahn
Copy link
Member

gibfahn commented Jun 17, 2017

cc/ @nodejs/streams

@addaleax addaleax added the confirmed-bug Issues with confirmed bugs. label Jun 18, 2017
addaleax added a commit to addaleax/node that referenced this issue Jun 18, 2017
Fixes `this.push(undefined)`.

Fixes: nodejs#13753
addaleax added a commit that referenced this issue Jun 21, 2017
Fixes `this.push(undefined)`.

Fixes: #13753
PR-URL: #13760
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Calvin Metcalf <calvin.metcalf@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

No branches or pull requests

3 participants