0

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 ?

  • It is very likely that it's the same issue as [this one](https://stackoverflow.com/questions/26163089/chrome-native-messaging-doesnt-accept-messages-of-certain-sizes-windows). So, to confirm: 1) are you on Windows? 2) do you take special steps to ensure the stream is treated as binary? – Xan Sep 18 '17 at 08:49
  • Why don't you use this method for reading data: uint32_t json_data_length = 0; // Read 4 bytes of length information from the command for (uint32_t length_count = 0; length_count < 4; length_count++) { int32_t read_char = ::getchar(); json_data_length |= (read_char << (length_count << 3)); } – Asesh Sep 19 '17 at 15:35
  • Are you saying that this happens on all three browsers? Which browser versions? Which operating system? Have your tried other operating systems? – Makyen Sep 22 '17 at 02:53
  • @Asesh It sounds great!I will try this way. Thank you! – user7412770 Sep 28 '17 at 09:32

0 Answers0