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

Unhandled error thrown when decoding stream with invalid data #75

Open
hzqst opened this issue Jul 26, 2017 · 2 comments
Open

Unhandled error thrown when decoding stream with invalid data #75

hzqst opened this issue Jul 26, 2017 · 2 comments

Comments

@hzqst
Copy link

hzqst commented Jul 26, 2017

var decodeStream = msgpack.createDecodeStream();
stream.pipe(decodeStream).on('data', function(data){ 
		console.log(data);
	}).on('error', function(err) {
		console.log(err);
    }).on("end", function(){ 

});

when you push invalid data into stream that is not the regular msgpack format, an errror will be thrown and the node process will die.
I found no way to catch this error. (trycatch doesn't work, neither does the error event listener).


 C:\Users\Administrator\Desktop\WsServer\node_modules\msgpack-lite\lib\flex-buffer.js:52

        if (e && e.message != BUFFER_SHORTAGE) throw e;
                                               ^

Error: Invalid type: 0xc1
    at decode (C:\Users\Administrator\Desktop\WsServer\node_modules\msgpack-lite\lib\re
ad-core.js:24:22)
    at map_to_obj (C:\Users\Administrator\Desktop\WsServer\node_modules\msgpack-lite\li
b\read-format.js:52:12)
    at C:\Users\Administrator\Desktop\WsServer\node_modules\msgpack-lite\lib\read-token
.js:153:12
    at decode (C:\Users\Administrator\Desktop\WsServer\node_modules\msgpack-lite\lib\re
ad-core.js:25:12)
    at map_to_obj (C:\Users\Administrator\Desktop\WsServer\node_modules\msgpack-lite\li
b\read-format.js:51:12)
    at C:\Users\Administrator\Desktop\WsServer\node_modules\msgpack-lite\lib\read-token
.js:153:12
    at decode (C:\Users\Administrator\Desktop\WsServer\node_modules\msgpack-lite\lib\re
ad-core.js:25:12)
    at map_to_obj (C:\Users\Administrator\Desktop\WsServer\node_modules\msgpack-lite\li
b\read-format.js:51:12)
    at C:\Users\Administrator\Desktop\WsServer\node_modules\msgpack-lite\lib\read-token
.js:153:12
    at decode (C:\Users\Administrator\Desktop\WsServer\node_modules\msgpack-lite\lib\re
ad-core.js:25:12)
    at map_to_obj (C:\Users\Administrator\Desktop\WsServer\node_modules\msgpack-lite\li
b\read-format.js:51:12)
    at C:\Users\Administrator\Desktop\WsServer\node_modules\msgpack-lite\lib\read-token
.js:153:12
    at decode (C:\Users\Administrator\Desktop\WsServer\node_modules\msgpack-lite\lib\re
ad-core.js:25:12)
    at map_to_obj (C:\Users\Administrator\Desktop\WsServer\node_modules\msgpack-lite\li
b\read-format.js:51:12)
    at C:\Users\Administrator\Desktop\WsServer\node_modules\msgpack-lite\lib\read-token
.js:153:12
    at decode (C:\Users\Administrator\Desktop\WsServer\node_modules\msgpack-lite\lib\re
ad-core.js:25:12)
@hzqst hzqst changed the title Unhandled error thrown while decoding stream with flowing mode Unhandled error thrown when decoding stream with invalid data Jul 26, 2017
@thetutlage
Copy link

Yes facing the same issue

@royaltm
Copy link

royaltm commented Jan 12, 2018

The culprit: https://github.com/kawanet/msgpack-lite/blob/master/lib/decode-stream.js#L30

var { createDecodeStream } = require('msgpack-lite');

function test() {
  createDecodeStream()
  .on('error', err => console.error('from handler: %s', err))
  .on('data', data=>console.log(data))
  .end(Buffer.from([0xc1]))
}

test();

Error: Invalid type: 0xc1
    at Codec.decode..............

createDecodeStream.prototype._transform = function(chunk, encoding, callback) {
  this.decoder.write(chunk);
  try {
    this.decoder.flush();
  } catch(err) {
    return callback(err);
  };
  callback();
};

test();

from handler: Error: Invalid type: 0xc1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants