Skip to content

Commit

Permalink
THRIFT-5569: add negative size checks in Go generator when reading ma…
Browse files Browse the repository at this point in the history
…ps, sets and lists

Client: go
  • Loading branch information
akrennmair authored and Jens-G committed Apr 20, 2022
1 parent edcad98 commit 8987820
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions compiler/cpp/src/thrift/generate/t_go_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3369,20 +3369,29 @@ void t_go_generator::generate_deserialize_container(ostream& out,
// Declare variables, read header
if (ttype->is_map()) {
out << indent() << "_, _, size, err := iprot.ReadMapBegin(ctx)" << endl;
out << indent() << "if size < 0 {" << endl;
out << indent() << " return errors.New(\"map size is negative\")" << endl;
out << indent() << "}" << endl;
out << indent() << "if err != nil {" << endl;
out << indent() << " return thrift.PrependError(\"error reading map begin: \", err)" << endl;
out << indent() << "}" << endl;
out << indent() << "tMap := make(" << type_to_go_type(orig_type) << ", size)" << endl;
out << indent() << prefix << eq << " " << (pointer_field ? "&" : "") << "tMap" << endl;
} else if (ttype->is_set()) {
out << indent() << "_, size, err := iprot.ReadSetBegin(ctx)" << endl;
out << indent() << "if size < 0 {" << endl;
out << indent() << " return errors.New(\"set size is negative\")" << endl;
out << indent() << "}" << endl;
out << indent() << "if err != nil {" << endl;
out << indent() << " return thrift.PrependError(\"error reading set begin: \", err)" << endl;
out << indent() << "}" << endl;
out << indent() << "tSet := make(" << type_to_go_type(orig_type) << ", 0, size)" << endl;
out << indent() << prefix << eq << " " << (pointer_field ? "&" : "") << "tSet" << endl;
} else if (ttype->is_list()) {
out << indent() << "_, size, err := iprot.ReadListBegin(ctx)" << endl;
out << indent() << "if size < 0 {" << endl;
out << indent() << " return errors.New(\"list size is negative\")" << endl;
out << indent() << "}" << endl;
out << indent() << "if err != nil {" << endl;
out << indent() << " return thrift.PrependError(\"error reading list begin: \", err)" << endl;
out << indent() << "}" << endl;
Expand Down

0 comments on commit 8987820

Please sign in to comment.