Proto: Catch pogs panic
Catch panics when deserializing capnp messages using pogs.
This could happen on malformed input, see
@@ -134,7 +134,13 @@ func readRootFromReader(r io.Reader) (_ capnp.Struct, err error) {
}
// parseStruct parses a capnp struct into a Cerealizable instance.
-func parseStruct(c Cerealizable, s capnp.Struct) error {
+func parseStruct(c Cerealizable, s capnp.Struct) (err error) {
+ // Convert pogs panics to errors
+ defer func() {
+ if rec := recover(); rec != nil {
+ err = common.NewBasicError("pogs panic", nil, "panic", rec)
+ }
+ }()
if err := pogs.Extract(c, uint64(c.ProtoId()), s); err != nil {
return common.NewBasicError("Failed to extract struct from capnp message", err)
}
