ParseFromString cuts String at \x00

64 views
Skip to first unread message

Bowfish

unread,
Nov 18, 2019, 2:57:28 PM11/18/19
to Protocol Buffers
I want to parse a string with the c++ ParseFromString function. The string contains \x00. It seems that this function cuts the string at \x00. Is this possible?

Here is some debug output which I used to investigate this:

// This is before ParseFromString

response message
: "\n\x0F\b\x01\x10\x04\x19\x8D\xD2z\xBF\x00\x00\x00\x00(\x01\x10\x02\x1AX0V0\x10\x06\x07*\x86H\xCE=\x02\x01\x06\x05+\x81\x04\x00\n\x03""B\x00\x04\x87W\xBBw\xF3\xE8\xAD\xA8y\n\x9E\xA0\xC5\xF0.\xFD""e>L\xD1k\xE6\x80\xCBZ\xD2\x8E\x89?\xD6#\xFF(\xAF#J\x12\xB5\x17""db\xD8\xDCY?\x8B\x98\xFE\x15NL\x9B;\x8A\xE3\xC0\xF1\xC4\xA5;\x07\x86\xE6\xD5"
response length
: "6d000000"
response length
: 109
response message
: "\n\u000F\b\u0001\u0010\u0004\u0019��z�\u0000\u0000\u0000\u0000(\u0001\u0010\u0002\u001AX0V0\u0010\u0006\u0007*�H�=\u0002\u0001\u0006\u0005+�\u0004\u0000\n\u0003B\u0000\u0004�W�w�譨y\n����.�e>L�k���ZҎ�?�#�(�#J\u0012�\u0017db��Y?���\u0015NL�;����ĥ;\u0007���"



// This is after I call the function from the protobuf Object which should extract the public key
// But the public key should be much longer. It shows only the part which is before \x00
0V0*�H�=+�
public key raw: "0V0\x10\x06\x07*\x86H\xCE=\x02\x01\x06\x05+\x81\x04"
0V0*�H�=+�
public key raw: "0V0\x10\x06\x07*\x86H\xCE=\x02\x01\x06\x05+\x81\x04"
public key hex: "3056301006072a8648ce3d020106052b8104"

Thanks for your help

Adam Cozzette

unread,
Nov 18, 2019, 3:08:20 PM11/18/19
to Bowfish, Protocol Buffers
Could you post a snippet of your C++ code that calls ParseFromString()?

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/475d2744-ed86-458a-a78e-263e38b22366%40googlegroups.com.

Bowfish

unread,
Nov 18, 2019, 3:34:41 PM11/18/19
to Protocol Buffers

void ArcaDbSetRequest::on_responseSuccessful(const QByteArray length, const QByteArray message)
{
    Q_UNUSED
(length)

   
// Create a new CryptoResponse
    arca_db
::DatabaseSetResponse *m_arcaDatabaseSetResponse = new arca_db::DatabaseSetResponse();
   
// Parse the message and convert it to a std::string
    m_arcaDatabaseSetResponse
->ParseFromString(message.toStdString());
   
// Extract the header of the response
    arca_firmware
::FirmwareMessageHeader header = m_arcaDatabaseSetResponse->header();

    qDebug
() << "header {";
    qDebug
() << "\tversion : " << header.version();
    qDebug
() << "\tservice : " << header.service();
    qDebug
() << "\tpeer_id : " << header.peer_id();
    qDebug
() << "\tresponse: " << header.response();
    qDebug
() << "\terror   : " << QString::fromStdString(header.error());
    qDebug
() << "}";
}

Adam Cozzette

unread,
Nov 18, 2019, 3:41:41 PM11/18/19
to Bowfish, Protocol Buffers
What's the return value of ParseFromString()? I would guess that it might be returning false because of a problem with the serialized data.

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.

Bowfish

unread,
Nov 18, 2019, 3:49:03 PM11/18/19
to Protocol Buffers

void ArcaCryptoNewKey::on_responseSuccessful(const QByteArray length, const QByteArray message)
{
    Q_UNUSED
(length)

   
// Parse the message and convert it to a std::string
    m_cryptoNewKeyResponse
->ParseFromString(message.toStdString());

    qDebug
() << "response length :" << length.toHex();
    qDebug
() << "response length :" << message.toStdString().length();
    qDebug
() << "response message:" << QString::fromStdString(message.toStdString());


   
// Extract the header of the response

    ar_firmware
::FirmwareMessageHeader header = m_cryptoNewKeyResponse->header();

   
this->printHeader(header);

   
QByteArray publicKey(m_cryptoNewKeyResponse->public_key().c_str());
    qDebug
() << "public key raw:" <<  publicKey;

    emit responseReceivedNewKey
();
}


To unsubscribe from this group and stop receiving emails from it, send an email to prot...@googlegroups.com.

Bowfish

unread,
Nov 18, 2019, 3:49:45 PM11/18/19
to Protocol Buffers
ParseFromString returns true

Boris Pitel

unread,
Nov 18, 2019, 9:31:04 PM11/18/19
to Protocol Buffers
Is it possible at all that serialized object stream contaons zero?
To unsubscribe from this group and stop receiving emails from it, send an email to prot...@googlegroups.com.

Bowfish

unread,
Nov 19, 2019, 1:47:13 AM11/19/19
to Protocol Buffers
No. That is the serialized object stream:

\n\x0F\b\x01\x10\x04\x19\xDE\x93\xC3""5\x00\x00\x00\x00(\x01\x10\x02\x1AX0V0\x10\x06\x07*\x86H\xCE=\x02\x01\x06\x05+\x81\x04\x00\n\x03""B\x00\x04\xC9""2oN\xBD""2\xA6\xF5\xCDVN\x16\xAD\x8B;L\xCB\xF4\xF1\x17""a\\z\xE5""A\x94\xEA:\xC2\x11}\x98V\xE5\xA1\xBF\x95\xF3\xD5,\n\x86o;\xB8\xC4x\x9A+\x94\xF9\x94g\x1B\xB3\xF0\x18@\x87\x88\x8C\x13\x8B\x01

The part of the stream which is marked bold can be read, but the rest of the stream will be cut off from ParseFromString.

Adam Cozzette

unread,
Nov 19, 2019, 12:42:20 PM11/19/19
to Bowfish, Protocol Buffers
If I remember right, the C++ parser has an undocumented behavior that it will immediately end upon encountering a zero tag. That could possibly be what is happening, but ordinarily there should never be a zero tag unless the data somehow got corrupted. Maybe an extra zero byte was added there by accident--you could try removing that zero byte and see if that fixes the problem.

To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/b421fde7-5094-461d-9276-958589692c8a%40googlegroups.com.

Bowfish

unread,
Nov 19, 2019, 2:49:03 PM11/19/19
to Protocol Buffers
Indeed. If I replace all \0x00 with \0x01 it is working.

Bowfish

unread,
Nov 19, 2019, 2:51:45 PM11/19/19
to Protocol Buffers
Can anybody recommend a workaround? Would it work with ParseFromArray?
Reply all
Reply to author
Forward
0 new messages