Trying out ProtoBuffers for streaming. I was hoping to exploit some
internal ProtoBuf-code for a streaming-protocol. The streaming-
protocol is basically the same as the message-internal protocol used
by ProtoBuf:

 [MSGTYPE(varint)] [LENGTH(varint)] [MESSAGE(blob)].

My attempt was to simply CodedInputStream::ReadTag() +
internal::WireFormatLite::ReadMessageNoVirtual() (which should AFAIU
read a length-prefixed message). However, I hit an error that I traced
down to ReadMessageNoVirtual returning true, even when the not the
entire LENGTH of the message was available on the CodedInputStream.

For my particular example, I'll probably rewrite it to read the outer-
message length externally in CodedInputStream and have the checks
there, but couldn't this be a failing validation for embedded streams
as well? I.E. one message of say, 40 bytes claiming to include a 60-
byte sub-message?

It seems to me that particular condition could be easily checked for
by extending ReadMessageNoVirtual with a check:

  uint32 length;
  if (!input->ReadVarint32(&length)) return false;
+  int bytesLeft = input->BytesUntilLimit();
+  if ((bytesLeft >= 0) && (length > bytesLeft)) return false;
  if (!input->IncrementRecursionDepth()) return false;
  io::CodedInputStream::Limit limit = input->PushLimit(length);

Just a thought.

You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to protobuf@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to