File tree Expand file tree Collapse file tree 1 file changed +3
-1
lines changed
src/google/protobuf/compiler/java Expand file tree Collapse file tree 1 file changed +3
-1
lines changed Original file line number Diff line number Diff line change @@ -971,10 +971,12 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuilderParsingCode(
971
971
void RepeatedImmutablePrimitiveFieldGenerator::
972
972
GenerateBuilderParsingCodeFromPacked (io::Printer* printer) const {
973
973
if (FixedSize (GetType (descriptor_)) != -1 ) {
974
+ // 4K limit on pre-allocations to prevent OOM from malformed input.
974
975
printer->Print (variables_,
975
976
" int length = input.readRawVarint32();\n "
976
977
" int limit = input.pushLimit(length);\n "
977
- " ensure$capitalized_name$IsMutable(length / $fixed_size$);\n "
978
+ " int alloc = length > 4096 ? 4096 : length;\n "
979
+ " ensure$capitalized_name$IsMutable(alloc / $fixed_size$);\n "
978
980
" while (input.getBytesUntilLimit() > 0) {\n "
979
981
" $repeated_add$(input.read$capitalized_type$());\n "
980
982
" }\n "
You can’t perform that action at this time.
0 commit comments