I'm getting this warning and an error afterwards when I try to parse a large message. I know than 64MB which is the default limit. I am using message.ParseFromIstream now. Does any one know to get access to CodedInputStream object to call the SetTotalBytesLimit function? or any other way to solve this problem?
Reading dangerously large protocol message. If the message turns out to be larger than 67108864 bytes, parsing will be halted for security reasons. To increase the limit (or to disable these warnings), see CodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h.
Here's a comment from the code (
google/protobuf/io/coded_stream.h
) that sets the message limit for those who's wondering what is the security reason they are talking about. In my case I cannot modify how my application work so I have to change this limit.This thread is quite old, but recently deep learning has got attention and the library Caffe used Protobuf so maybe more people will stumbled upon this. I have to do neural network stuff with Caffe, and the whole network took so much memory even with smallest batch size.
The correct fix: You should try to limit the sizes of your protobuf messages. Please see: https://developers.google.com/protocol-buffers/docs/techniques#streaming
The quick and dirty (read not recommended) approach: In the file coded_stream.h of the protobuf library source, change the values of
kDefaultTotalBytesLimit
andkDefaultTotalBytesWarningThreshold
, recompile, and reinstall.Just reading the documentation of the function that the error already told you about, would've answered that question:
Source
Also it's probably a really good idea to follow the first part of the advice and redesign the application.