google / google/libprotobuf-mutator

Mutator breaks content of Any

Open
#221 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
667
Forks
134
PR merge metrics
No merged PRs in 30d

Description

Library version: v1.1

Proto:
```
syntax = "proto2";

import "google/protobuf/any.proto";

message Hello {
optional string field = 1;
optional google.protobuf.Any content = 2;
}

message Content1 {
optional string field = 1;
}

message Content2 {
optional string field = 1;
}

```

Code:
```
#include

#include "src/text_format.h"
#include "src/mutator.h"
#include "hello.pb.h"

int main() {
Hello he;

Content1 c1;
c1.set_field("field1");
auto a = new google::protobuf::Any();
a->PackFrom(c1);
he.set_allocated_content(a);

std::cerr << "data:" << protobuf_mutator::SaveMessageAsText(he) << std::endl;

protobuf_mutator::Mutator mutator;
mutator.Seed(1);

mutator.Mutate(&he, 10000);
mutator.Fix(&he);
std::cerr << "data:" << protobuf_mutator::SaveMessageAsText(he) << std::endl;
}
```

Current result:
```
data:content {
type_url: "type.googleapis.com/Content1"
value: "\n\006field1"
}

data:content {
type_url: "type.gogleapi.\303\225om/Content1"
value: "\n\006field1"
}
```
Field 'type_url' is broken and application will not accept this message. It's also possible to get a broken (unparsable) field 'value'.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.