Bugfix: Ostinato GUI crash when response from Drone is split into multiple frames - the message is parsed incompletely and subsequent frame which starts in the middle of the previous message is interpreted as start of new message leading to the crash. With this fix we are effectively not able to use zero copy as originally intended. To use zero-copy we need to make a blocking call which means we need to do this in a new thread. Till that time this fix will avoid the crash and do the correct thing.

This commit is contained in:
Srivats P 2016-01-04 20:30:05 +05:30
parent 414d89860d
commit 133a83f139

View File

@ -256,6 +256,11 @@ _top:
}
case PB_MSG_TYPE_RESPONSE:
{
static quint32 cumLen = 0;
static QByteArray buffer;
int l = 0;
if (!isPending)
{
qWarning("not waiting for response");
@ -269,8 +274,35 @@ _top:
goto _error_exit;
}
msgLen = 0;
while (cumLen < len)
{
if (inStream->Next((const void**)&msg, &msgLen) == false) {
//qDebug("No more data or stream error");
goto _exit;
}
l = qMin(msgLen, int(len - cumLen));
buffer.append(QByteArray((char*)msg, l));
cumLen += l;
//qDebug("%s: buffer rcvd %d/%d/%d", __PRETTY_FUNCTION__, l, cumLen, len);
}
if (l < msgLen) {
qDebug("read extra bytes after response; putting back");
inStream->BackUp(msgLen - l);
}
#if 0 // not needed?
if (cumLen < len)
goto _exit;
#endif
if (len)
response->ParseFromBoundedZeroCopyStream(inStream, len);
response->ParseFromArray((const void*)buffer, len);
cumLen = 0;
buffer.resize(0);
// Avoid printing stats
if (method != 13)
@ -290,7 +322,7 @@ _top:
controller->SetFailed("Required fields missing");
}
break;
}
case PB_MSG_TYPE_ERROR:
{
static quint32 cumLen = 0;