Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mutator breaks content of Any #221

Open
sievlev opened this issue Apr 27, 2023 · 0 comments
Open

Mutator breaks content of Any #221

sievlev opened this issue Apr 27, 2023 · 0 comments

Comments

@sievlev
Copy link

sievlev commented Apr 27, 2023

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 <iostream>

#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'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant