-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Index out of Range Exception Randomely #907
Comments
I have the same problem that it randomly throws Index out of Range Exception. Did you solve it? |
One thing I notice there is that |
@dcodeIO I used python django channels to send protobuf bytes data to the browser. I compare the the bytes data of the |
I don't know what |
@dcodeIO I find the there is something different from the bytes data I sent from python and the Bytes data send from python:18,150,1,8,3,18,4,84,97,111,66,34,55,47,109,101,100,105,97,47,117,115,101,114,47,112,104,111,116,111,47,50,48,49,54,47,49,49,47,50,52,47,81,81,229,155,190,231,137,135,50,48,49,54,49,49,50,51,50,48,50,56,53,56,46,112,110,103,40,206,183,160,216,5,50,33,109,101,100,105,97,47,117,115,101,114,47,51,47,49,95,50,48,49,56,48,53,50,53,50,50,50,49,48,50,46,100,111,99,56,128,168,147,1,66,5,49,46,100,111,99,51,220,236,109,97,170,194,130,112,227,129,178,43,193,56,119,182,187,95,133,2,235,26,9,232,159,138,68,225,51,30,170 I receive Blob in the client browser and I use
|
Things like these usually happen when the data is forced into some sort of string encoding like utf8. The best way to avoid this is to make sure that the data remains binary from its generation to its consumption, or, if string conversion is necessary for some reason, use base64 encoding. |
@dcodeIO In my case, the data server sent to client is binary. The client receives it using Websocket as Blob, and converts it to |
Hard to tell, but using a |
@dcodeIO Thank you for the advice. I've replaced |
@dcodeIO Sorry to bother you again. Even the same bytes data cannot be decoded in the browser. in Python
in browser
And the Error
Here is my .proto file
I don't know what's wrong in this. |
Same issue. Works fine with identical data in python but not in js. Any solution? |
请问 解决了吗 |
Hi, I just met the same issue and solve it via patching protobufjs with the following tricky code in diff --git a/src/decoder.js b/src/decoder.js
index 491dd3059df42d28c2f486e89651985433f650c6..53f6ef95e069b36e627a859301b9495391ec60d6 100644
--- a/src/decoder.js
+++ b/src/decoder.js
@@ -59,6 +59,14 @@ function decoder(mtype) {
("case 2:");
if (types.basic[type] === undefined) gen
+ ("if (2 !== (t&7)) {")
+ ("r.skipType(t&7)")
+ ("break")
+ ("}")
("value=types[%i].decode(r,r.uint32())", i); // can't be groups
else gen
("value=r.%s()", type);
@@ -91,14 +99,29 @@ function decoder(mtype) {
("}else");
// Non-packed
- if (types.basic[type] === undefined) gen(field.resolvedType.group
+ if (types.basic[type] === undefined) gen
+ ("if (2 !== (t&7)) {")
+ ("r.skipType(t&7)")
+ ("break")
+ ("}")
+ (field.resolvedType.group
? "%s.push(types[%i].decode(r))"
: "%s.push(types[%i].decode(r,r.uint32()))", ref, i);
else gen
("%s.push(r.%s())", ref, type);
// Non-repeated
- } else if (types.basic[type] === undefined) gen(field.resolvedType.group
+ } else if (types.basic[type] === undefined) gen
+ ("if (2 !== (t&7)) {")
+ ("r.skipType(t&7)")
+ ("break")
+ ("}")
+ (field.resolvedType.group
? "%s=types[%i].decode(r)"
: "%s=types[%i].decode(r,r.uint32())", ref, i);
else gen I also create a fork with the fix here: icyzeroice@53f6ef9 The reason why I got this error is that the protobuf data I use has some invalid messages only have the field name and wrong wire type without the field value in it. So, I skip decoding this kind of empty data with wrong wire type. I do not know if there are other new problems with the solution, but it just works fine. PS: I came into two different errors, and both of them are solved with the patch above.
|
Hi. I have very same issue. This is opened for 5 years now so I wanna ask if this is even considered as a issue in |
FYI: I was able to get rid off exception. The problem was probably in the content itself. Originally, my main content was encrypted using the JSEncrypt and crypto-js libraries. After switching to using only the web crypto API that works with ArrayBuffer, I no longer get the Index out of range exception. Therefore, I think the problem is related to the encoding of the content. |
what's the fix for this |
I ran into this issue with an object/message that was all strings. It would randomly fail depending on the values passed in and sometimes even the order of the elements in the object. I resolved this by using |
I was able to fix mine. It was a pub sub pattern and one of the pairs had a missing field |
protobuf.js version: <6.8.0>
I am getting an index out of range exception randomly,



when I am subscribing a message from a server which is a console application,
this is the code snippet which is sending the message.
and the below is the JS snippet where the data is recieved but on continous recieving the protobufjs is throwing an index out of range exception randomely where I tried to read the data after the four bytes of the Sentmessage.
and the exception I am getting is
I am also facing an invalid wire type exception randomly and very rare.
Can anyone help me out getting the data continuously and root cause of the issue.
The text was updated successfully, but these errors were encountered: