Open EFanZh opened 1 year ago
The way I see it, struct Foo
can never be constructed. prost will create a default instance of Foo during decoding, which will stack overflow.
The C++ implementation solves this by using the same API for optional and required fields and doing lazy initialization. That way, it doesn't have to create the full instance. https://protobuf.dev/reference/cpp/cpp-generated/#embeddedmessage
I don't know how to solve this besides throwing an error during prost-build
. Is this a real-world example, or did you find out about this during experimentation?
I kind of forget then exact context of this issue. But I think is is not a very urgent issue.
Suppose I have a proto file with a recursive message:
prost-build
will generate this struct:If I use the
Foo
type to decode an empty byte slice, I get an stack overflow error:I guess the behavior is caused by
prost
attempting to construct aFoo
object, which is not possible, since constructing it recursively depends on constructing a new object of the same type.