AAPT2: Increase maximum proto size
Deserializing a proto form a string throws an error when 64MB have been
read from the stream. This change removes the maximum size but shows a
warning when a proto is larger than 64MB.
Bug: 114020398
Test: manual test with resources.pb greater than 64MB
Change-Id: Iee397b6709d79a9338133a6136fe6e8f70a4964c
diff --git a/tools/aapt2/io/Util.h b/tools/aapt2/io/Util.h
index b07fb53..5f978a8 100644
--- a/tools/aapt2/io/Util.h
+++ b/tools/aapt2/io/Util.h
@@ -20,6 +20,7 @@
#include <string>
#include "google/protobuf/message_lite.h"
+#include "google/protobuf/io/coded_stream.h"
#include "format/Archive.h"
#include "io/File.h"
@@ -122,6 +123,23 @@
io::InputStream* in_;
};
+class ProtoInputStreamReader {
+ public:
+ explicit ProtoInputStreamReader(io::InputStream* in) : in_(in) { }
+
+ /** Deserializes a MessageLite proto from the current position in the input stream.*/
+ template <typename T> bool ReadMessage(T *message_lite) {
+ ZeroCopyInputAdaptor adapter(in_);
+ google::protobuf::io::CodedInputStream coded_stream(&adapter);
+ coded_stream.SetTotalBytesLimit(std::numeric_limits<int32_t>::max(),
+ coded_stream.BytesUntilTotalBytesLimit());
+ return message_lite->ParseFromCodedStream(&coded_stream);
+ }
+
+ private:
+ io::InputStream* in_;
+};
+
} // namespace io
} // namespace aapt