Skip to content

Any::PackFrom broken in protobuf 33.0 (regression) #24258

@juergbi

Description

@juergbi

What version of protobuf and what language are you using?
Version:33.0
Language: C++

What operating system (Linux, Windows, ...) and version?
Linux 6.17

What runtime / compiler are you using (e.g., python version or gcc version)
GCC 15.2

What did you do?
Test code to reproduce the issue:

#include <iostream>

#include <google/protobuf/any.pb.h>
#include <google/protobuf/wrappers.pb.h>

int main(int argc, char **argv)
{
    google::protobuf::StringValue stringValue1;
    stringValue1.set_value("hello, world");

    google::protobuf::Any any1;
    any1.PackFrom(stringValue1);

    // The following statement works around the issue:
    // any1.mutable_value();

    const auto anySerialized = any1.SerializeAsString();

    google::protobuf::Any any2;
    if (!any2.ParseFromString(anySerialized)) {
        return 2;
    }

    google::protobuf::StringValue stringValue2;
    any2.UnpackTo(&stringValue2);

    std::cout << "Unpacked string: " << stringValue2.value() << std::endl;

    return stringValue2.value() == "hello, world" ? 0 : 1;
}

Compile e.g. with g++ -o anytest $(pkg-config --cflags --libs protobuf) anytest.cc

What did you expect to see
Unpacked string: hello, world and exit code 0.

What did you see instead?
Unpacked string: and exit code 1.

This is a regression in 33.0, which was introduced in #22956 in combination with the auto-generated commit be95d77. @ClaytonKnittel, please take a look.

As I understand it, the issue is that Any::PackFrom uses _internal_mutable_value(), which used to call SetHasBit() but no longer does with the change mentioned above. This results in serialization skipping the Any.value field even though it is set.

This breaks https://gitlab.com/BuildGrid/buildbox/buildbox/.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions