fuwaneko / node-protobuf

Google Protocol Buffers wrapper for Node.js [UNMAINTAINED]
179 stars 42 forks source link

Parsing bad data causes a segmentation fault #9

Closed jeffhiltz closed 11 years ago

jeffhiltz commented 11 years ago

There is a chance that the protobuf data that I'm trying to parse is invalid. If I pass invalid data to the Parse function (as in sample below) I get a segmentation fault.

Would it be possible to catch the fault and return an Error object or throw an Error?

var fs = require("fs")
var p = require("node-protobuf").Protobuf
var pb = new p(fs.readFileSync("protocol.desc"))

var newObj = pb.Parse('invalid data', "MySchema")

Thanks.

fuwaneko commented 11 years ago

Interestingly on Windows I don't get any errors, but nothing is returned as well. I'll fix it soon, thanks for reporting.

fuwaneko commented 11 years ago
// throws "Malformed protocol buffer"
newObj = pb.Parse(new Buffer("Bad buffer"), "Test")
// throws "First argument must be a Buffer"
newObj = pb.Parse("Bad argument", "Test")