Skip to content
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

"Invalid wire type n" "index out of range: n + 1 > n" #1927

Open
KiillThemAll opened this issue Aug 23, 2023 · 11 comments
Open

"Invalid wire type n" "index out of range: n + 1 > n" #1927

KiillThemAll opened this issue Aug 23, 2023 · 11 comments

Comments

@KiillThemAll
Copy link

protobuf.js version: 7.2.4
imported node module

Different errors on decode by pbjs in case of uint64 value with tags 2 or 3 or 4. With other tags everything is fine.
!Data is sent in binary everywhere and remains the same!
Suppose, something with decoding procedure.
Errors:
"Invalid wire type n"
"index out of range: n + 1 > n"

This error have been mentioned in other issues, but in other circumstances and no clues so far.
#987
#1297
#907
#991
#1049
#1063
and others

To reproduce:

Proto message:

message PlaceAction{
  uint64 place_id = 1;
  string action = 2;
  string url = 3;
  uint64 city_id = 4;
}

Generate by pbjs with long!

Generated decode func:

PlaceAction.decode = function decode (reader, length) {
      if (!(reader instanceof $Reader)) { reader = $Reader.create(reader); }
      let end = length === undefined ? reader.len : reader.pos + length; let message = new $root.object_msg.PlaceAction();
      while (reader.pos < end) {
        let tag = reader.uint32();
        switch (tag >>> 3) {
          case 1: {
            message.place_id = reader.uint64();
            break;
          }
          case 2: {
            message.action = reader.string();
            break;
          }
          case 3: {
            message.url = reader.string();
            break;
          }
          case 4: {
            message.city_id = reader.uint64();
            break;
          }
          default:
            reader.skipType(tag & 7);
            break;
        }
      }
      return message;
    };

Example stack trace:

index out of range: 18 + 1 > 18
RangeError: index out of range: 18 + 1 > 18
at indexOutOfRange (http://localhost:8080/js/chunk-vendors.js:17476:12)
at Reader.skip (http://localhost:8080/js/chunk-vendors.js:17807:23)
at push../node_modules/protobufjs/src/reader.js.Reader.skipType (http://localhost:8080/js/chunk-vendors.js:17821:18)
at Function.decode (http://localhost:8080/js/app.js:5454:20)
at Function.decode (http://localhost:8080/js/app.js:5586:63)

@KiillThemAll
Copy link
Author

Incremented city_id tag to 5 and everything works as expected. But this is bad solution.

@alexander-fenster
Copy link
Contributor

Oh wow, that must be a cool bug somewhere. I will try to figure out what's going on, thank you!

@KiillThemAll
Copy link
Author

Looking forward to your investigation, such errors could lead to extremely unpredictable behaviour.

@KiillThemAll
Copy link
Author

Another recent issue:
#1920

@UCoyote
Copy link

UCoyote commented Aug 28, 2023

I had the same problem。Change the data type to uint32 and everything works as expected

@pine-serpent
Copy link

i have this issue in my mollysocket docker container:

[2024-10-28T03:57:36Z ERROR mollysocket::ws::websocket_connection] Failed to decode protobuf: failed to decode Protobuf message: invalid wire type value: 7
[2024-10-28T03:57:36Z WARN mollysocket::ws::websocket_connection] Websocket finished

how can i apply the above fix for this?

thank you for any help you can provide.

@KiillThemAll
Copy link
Author

@pine-serpent
Just do not use int64 and uint64 with tags 2, 3, 4

@KiillThemAll
Copy link
Author

Oh wow, that must be a cool bug somewhere. I will try to figure out what's going on, thank you!

@alexander-fenster
Any clues?
Really old and annoying bug.
We have to skip these tags in production project every time...

@JungminByun
Copy link

JungminByun commented Feb 18, 2025

protobuf.js version: 7.4.0

It keeps printing the message "invalid wire type 6"
Protobuf is created as uint64 and the type cannot be changed

type = uint64
tag = 2

How do I solve this?
Has anyone solved it?

@KiillThemAll
Copy link
Author

@JungminByun
Just do not use int64 and uint64 with tags 2, 3, 4
Its the only solution that works

@JungminByun
Copy link

@KiillThemAll
I saw above that you should not use int64 and uint64 with tags 2, 3, 4.
I did not create the data, the data is already defined that way. (int64 and uint64 with tags 2, 3, 4.)
Is there a workaround for this?

For example, is it okay to change tags?

[AS IS]
message Road {
int32 seq = 1;
uint64 linkLength = 2;
uint64 linkID = 3;
}

[TO BE]
message Road {
int32 seq = 1;
uint64 linkLength = 5;
uint64 linkID = 6;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants