From f4f9aec52f5b4c46ff32fb9527229da081a14e11 Mon Sep 17 00:00:00 2001 From: Petr Prokhorenkov Date: Thu, 14 Apr 2016 11:17:54 +0300 Subject: Fix bug with silent message corruption in LITE_RUNTIME. A protobuf message will be corrupted in the following scenario: 1. Use LITE_RUNTIME. 2. Have an optional enum field following some other field. 3. Update protocol by adding new values to the enum. 4. Have an old client parse and serialize a message having enum field set to a value the client does not understand. 5. Field preceeding the enum is now corrupted. The bug is due to the fact that optimized fallthrough in parser code does not update variablle 'tag' when jumping to the parser code for the next field. --- src/google/protobuf/compiler/cpp/cpp_enum_field.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/google/protobuf/compiler/cpp/cpp_enum_field.cc') diff --git a/src/google/protobuf/compiler/cpp/cpp_enum_field.cc b/src/google/protobuf/compiler/cpp/cpp_enum_field.cc index 824e2205..06cb18d1 100644 --- a/src/google/protobuf/compiler/cpp/cpp_enum_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_enum_field.cc @@ -36,6 +36,7 @@ #include #include #include +#include namespace google { namespace protobuf { @@ -142,8 +143,9 @@ GenerateMergeFromCodedStream(io::Printer* printer) const { } else { printer->Print( "} else {\n" - " unknown_fields_stream.WriteVarint32(tag);\n" - " unknown_fields_stream.WriteVarint32(value);\n"); + " unknown_fields_stream.WriteVarint32($tag$);\n" + " unknown_fields_stream.WriteVarint32(value);\n", + "tag", SimpleItoa(internal::WireFormat::MakeTag(descriptor_))); } printer->Print(variables_, "}\n"); -- cgit v1.2.3