Recently, I am testing a extension with Native messaging protocol on the chrome,firefox and opera.There is a problem that would always crash the NativeApp on the specially appointed of our platform.

On debugging I find that the app would be crash and log: "error: only 0 could be read." in the special size of a message from the extension.

Through the loop test demo, the native app would fail to receive message when the size of the json message sent to the application is 282B,538B,794B,1050B,1306B,1562B,1818B,2074B...

Here is the function that reading a 32-bit value containing the message length to precede a message.

int InputParser::readMessageLengthFromStream() {
int result = 0;
char size[sizeof (int)];
CString str = "";
inputStream.read(size, sizeof (int));

//check the input
if (inputStream){
    Dlog("All characters read successfully!");
}
else{
    Dlog("error: only %d could be read.",inputStream.gcount());
    return -1;
}

for (int n = sizeof (int) - 1; n >= 0; n--) {
    result = (result << 8) + (unsigned char)size[n];
}
return result;
}

Do you have the same question?

Is there any solution to fix it ?

0

There are 0 answers