help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help fixing NativeMessaging host: read 32-bit message length in nati


From: guest271314
Subject: Re: Help fixing NativeMessaging host: read 32-bit message length in native byte order
Date: Sat, 24 Jun 2023 09:01:50 -0700

uname -a:

Linux xubuntu 5.15.0-43-generic #46-Ubuntu SMP Tue Jul 12 10:30:17 UTC 2022
x86_64 x86_64 x86_64 GNU/Linux.

I am testing on Chromium. Though you can use Firefox, too, if you prefer.
Installing a Native Messaging host on Firefox is a little different from
doing so on Chromium or Chrome, see
https://github.com/mdn/webextensions-examples/issues/506.



It took a while to write the same algorithm in different programming
languages https://github.com/guest271314/NativeMessagingHosts that also
reads and writes 1 MB. In JavaScript I had to write the algorithm
differently for each runtime. For all clients except Bash version I am
passing passing new Array(209715). JSON.stringify(new Array(209715)) is 1
MB, the maximum length of a single message from host to client. For Bash
version I am only passing new Array(408), then things go haywire when new
Array(409) is passed. The array in JSON winds up being [null, ..., null].

The instructions here
https://github.com/guest271314/native-messaging-quickjs/edit/main/README.md
detail how you can reproduce what I am doing yourself.



On Sat, Jun 24, 2023 at 8:21 AM Greg Wooledge <greg@wooledge.org> wrote:

> On Sat, Jun 24, 2023 at 08:10:39AM -0700, guest271314 wrote:
> > So, in the end, you can use something like this.
> >
> >   length=$(dd iflag=fullblock bs=4 count=1 | od -An -td4)
> >   length=$((length))      # trim leading spaces
> >   IFS= read -rN"$length" json
> >
> > That still winds up showing "Invalid byte sequence in conversion input"
> > when echo'ing the output to a file.
>
> Please show us the input.  Since it's binary, you'll need to represent
> it in some way that can fit into an e-mail body.  Perhaps a hex dump of
> the first 128 bytes or something.
>
> I'm rather curious what possible input could be an "invalid byte sequence"
> when interpreted as 32 bits that make up an integer.  Is it having the
> high bit set (meaning negative when read as a signed integer)?
>
> unicorn:~$ printf '\x00\x00\x00\x80' | od -An -td4
>  -2147483648
>
> Hmm, no, that looks all right to me.  Certainly didn't give that error.
>
> What operating system and architecture are you on, and what input are you
> using to generate this message, and which program is actually writing it?
>
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]