Here's a comment from the code (google/protobuf/io/coded_stream.h
) che imposta il limite di messaggi per coloro che si chiedono quale sia il motivo di sicurezza di cui stanno parlando. Nel mio caso non posso modificare il modo in cui funziona la mia applicazione, quindi devo modificare questo limite.
Questo thread è piuttosto vecchio, ma recentemente l'apprendimento approfondito ha attirato l'attenzione e la libreria Caffe ha utilizzato Protobuf quindi forse più persone inciamperanno su questo. Devo fare cose di rete neurale con Caffe, e l'intera rete ha preso così tanta memoria anche con le dimensioni di batch più piccole.
// Total Bytes Limit -----------------------------------------------
// To prevent malicious users from sending excessively large messages
// and causing integer overflows or memory exhaustion, CodedInputStream
// imposes a hard limit on the total number of bytes it will read.
// Sets the maximum number of bytes that this CodedInputStream will read
// before refusing to continue. To prevent integer overflows in the
// protocol buffers implementation, as well as to prevent servers from
// allocating enormous amounts of memory to hold parsed messages, the
// maximum message length should be limited to the shortest length that
// will not harm usability. The theoretical shortest message that could
// cause integer overflows is 512MB. The default limit is 64MB. Apps
// should set shorter limits if possible. If warning_threshold is not -1,
// a warning will be printed to stderr after warning_threshold bytes are
// read. For backwards compatibility all negative values get squashed to -1,
// as other negative values might have special internal meanings.
// An error will always be printed to stderr if the limit is reached.
//
// This is unrelated to PushLimit()/PopLimit().
//
// Hint: If you are reading this because your program is printing a
// warning about dangerously large protocol messages, you may be
// confused about what to do next. The best option is to change your
// design such that excessively large messages are not necessary.
// For example, try to design file formats to consist of many small
// messages rather than a single large one. If this is infeasible,
// you will need to increase the limit. Chances are, though, that
// your code never constructs a CodedInputStream on which the limit
// can be set. You probably parse messages by calling things like
// Message::ParseFromString(). In this case, you will need to change
// your code to instead construct some sort of ZeroCopyInputStream
// (e.g. an ArrayInputStream), construct a CodedInputStream around
// that, then call Message::ParseFromCodedStream() instead. Then
// you can adjust the limit. Yes, it's more work, but you're doing
// something unusual.
Invece di proporre di gestire il proprio ramo del codice protobuf (ugh), si può semplicemente costruire manualmente il CodedInputStream e usarlo. La riprogettazione dell'applicazione sarebbe molto probabilmente l'opzione migliore, ma non c'è assolutamente alcun motivo per mantenere la propria filiale. – Voo
L'approccio rapido e sporco ha funzionato per me. Grazie. –