Skip to content

Commit

Permalink
fix a segfault when accessing a repeated field with an improper unico…
Browse files Browse the repository at this point in the history
…de string member
  • Loading branch information
robbywalker committed Aug 16, 2012
1 parent 706439d commit c2e6ef1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/fastpb/template/module.jinjacc
Expand Up @@ -168,17 +168,17 @@ namespace {
new google::protobuf::io::StringOutputStream(&result);
google::protobuf::io::CodedOutputStream* outputStream =
new google::protobuf::io::CodedOutputStream(output);

PyObject *sequence = PySequence_Fast(values, "The values to serialize must be a sequence.");
for (Py_ssize_t i = 0, len = PySequence_Length(sequence); i < len; ++i) {
{{ message.name }} *value = ({{ message.name }} *)PySequence_Fast_GET_ITEM(sequence, i);

Py_BEGIN_ALLOW_THREADS
outputStream->WriteVarint32(value->protobuf->ByteSize());
value->protobuf->SerializeToCodedStream(outputStream);
Py_END_ALLOW_THREADS
}

Py_XDECREF(sequence);
delete outputStream;
delete output;
Expand Down Expand Up @@ -297,6 +297,9 @@ namespace {
PyObject *value =
fastpb_convert{{ member.type if member.type != TYPE.MESSAGE else message.name + member.name }}(
self->protobuf->{{ member.name.lower() }}(i));
if (!value) {
return NULL;
}
PyTuple_SetItem(tuple, i, value);
}
return tuple;
Expand Down

0 comments on commit c2e6ef1

Please sign in to comment.