@ -62,11 +62,12 @@
#include "google/protobuf/arena.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/generated_message_reflection.h"
#include "google/protobuf/message.h"
#include "google/protobuf/generated_ message_tctable_impl .h"
#include "google/protobuf/io/coded_stream.h"
#include "google/protobuf/io/io_win32.h"
#include "google/protobuf/io/zero_copy_stream.h"
#include "google/protobuf/io/zero_copy_stream_impl.h"
#include "google/protobuf/message.h"
#include "google/protobuf/test_util2.h"
@ -1684,6 +1685,60 @@ class TestInputStream final : public io::ZeroCopyInputStream {
size_t break_pos_;
};
template < typename T >
static const internal::TcParseTableBase* GetTableIfAvailable(...) {
return nullptr;
}
template < typename T >
static const internal::TcParseTableBase* GetTableIfAvailable(
decltype(internal::TcParser::GetTable< T > ())) {
return internal::TcParser::GetTable< T > ();
}
TEST(MESSAGE_TEST_NAME, TestRegressionInlinedStringAuxIdxMismatchOnFastParser) {
using Proto = UNITTEST::InlinedStringIdxRegressionProto;
auto* table = GetTableIfAvailable< Proto > (nullptr);
// Only test when TDP is on, and we have these fields inlined.
if (table != nullptr & &
table->fast_entry(1)->target() == internal::TcParser::FastSiS1) {
// optional string str1 = 1;
EXPECT_EQ(table->fast_entry(1)->bits.aux_idx(), 1);
// optional InlinedStringIdxRegressionProto sub = 2;
EXPECT_EQ(table->fast_entry(2)->bits.aux_idx(), 2);
// optional string str2 = 3;
// The aux_idx points to the inlined_string_idx and not the actual aux_idx.
EXPECT_EQ(table->fast_entry(3)->bits.aux_idx(), 2);
// optional string str3 = 4;
// The aux_idx points to the inlined_string_idx and not the actual aux_idx.
EXPECT_EQ(table->fast_entry(0)->bits.aux_idx(), 3);
}
std::string encoded;
{
Proto proto;
// We use strings longer than SSO.
proto.set_str1(std::string(100, 'a'));
proto.set_str2(std::string(100, 'a'));
proto.set_str3(std::string(100, 'a'));
encoded = proto.SerializeAsString();
}
Arena arena;
auto* proto = Arena::CreateMessage< Proto > (&arena);
// We don't alter donation here, so it works even if the idx are bad.
ASSERT_TRUE(proto->ParseFromString(encoded));
// Now we alter donation bits. str2's bit (#2) will be off, but its aux_idx
// (#3) will point to a donated string.
proto = Arena::CreateMessage< Proto > (&arena);
proto->mutable_str1();
proto->mutable_str2();
proto->mutable_str3();
// With the bug, this breaks the cleanup list, causing UB on arena
// destruction.
ASSERT_TRUE(proto->ParseFromString(encoded));
}
TEST(MESSAGE_TEST_NAME, TestRepeatedStringParsers) {
google::protobuf::Arena arena;