I am developing a Chrome extension that works with my own messaging server. It works in most cases, but I found strange behavior when sending messages of certain sizes. It seems that the message is discarded when the size is from 2560 to 2815 bytes (A00 and AFF in hexadecimal format). All subsequent messages are also not received, which indicates that the stream is damaged for some reason.
Here is a stripped down Python messaging application that you can use to test it:
import sys import struct def output(message): encoded_message = message.encode('utf-8')
I get the first message, not the second.
I looked at the code in the Chrome repository . A function that appears to be responsible for this functionality has nothing special:
void NativeMessageProcessHost::ProcessIncomingData( const char* data, int data_size) { DCHECK_CURRENTLY_ON(content::BrowserThread::IO); incoming_data_.append(data, data_size); while (true) { if (incoming_data_.size() < kMessageHeaderSize) return; size_t message_size = *reinterpret_cast<const uint32*>(incoming_data_.data()); if (message_size > kMaximumMessageSize) { LOG(ERROR) << "Native Messaging host tried sending a message that is " << message_size << " bytes long."; Close(kHostInputOuputError); return; } if (incoming_data_.size() < message_size + kMessageHeaderSize) return; content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, base::Bind(&Client::PostMessageFromNativeProcess, weak_client_ui_, destination_port_, incoming_data_.substr(kMessageHeaderSize, message_size))); incoming_data_.erase(0, kMessageHeaderSize + message_size); } }
Does anyone know what could be happening here?
Update
I ran into this issue on 64-bit versions of Windows 7 and Windows 8.1.
I tried the 64-bit version of Chrome on the Stable, Beta, and Dev channels - versions 37, 38, and 39. I also tried the stable 32-bit Chrome
I am using the 32-bit version of Python 2.7.7 and PyInstaller 2.1 to create an executable for my own messaging server.
c ++ python google-chrome-extension chrome-native-messaging
Slawek rewaj
source share