Protobuf: Segfault when attempting to serialize response object

Created on 3 Jul 2019  路  3Comments  路  Source: protocolbuffers/protobuf

What version of protobuf and what language are you using?
Version: 3.7.1
Language: PHP

What operating system (Linux, Windows, ...) and version?

Linux 4.9.0-7-amd64 #1 SMP Debian 4.9.110-3+deb9u2 (2018-08-13) x86_64 GNU/Linux

What runtime / compiler are you using (e.g., python version or gcc version)

Proto-c: libprotoc 3.7.1

I attempted to serialize (https://www.php.net/manual/en/function.serialize.php) a response object extending \Google\Protobuf\Internal\Message. I attempted this on all the generated response objects that where generated

What did you expect to see

A serialized string.

What did you see instead?

A segfault

I think this issue is similar (but not the same) as the issue in https://github.com/protocolbuffers/protobuf/issues/4107 but, instead of trying to mock it, I am trying to serialize it.

php

Most helpful comment

@TeBoring would it be possible to throw an exception with a useful error message instead of segfaulting? Or perhaps change the generated code to implement the __sleep magic method and serialize to proto there?

This segfault was difficult for us to track down in a large PHP codebase.

All 3 comments

The serialize function is not supported for protobuf message. Could you call the serialize method of proto message directly?

I was not aware that the proto messages had a serialize method. I'll try to use that.

Thank you for your response.

@TeBoring would it be possible to throw an exception with a useful error message instead of segfaulting? Or perhaps change the generated code to implement the __sleep magic method and serialize to proto there?

This segfault was difficult for us to track down in a large PHP codebase.

Was this page helpful?
0 / 5 - 0 ratings