Skip to content

Mutator breaks content of AnyΒ #221

@sievlev

Description

@sievlev

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions