rumblefrog / go-a2s

Golang implementation of Source Query
MIT License
66 stars 16 forks source link

Runtime error under linux/ubuntu with player query #3

Closed Sir-Will closed 3 years ago

Sir-Will commented 3 years ago

I'm getting the runtime error below when querying the players of 85.190.155.172:27015 under ubuntu.

When doing the same under windows it doesn't crash and just returns the error (wsarecv: A message sent on a datagram socket was larger than the internal message buffer or some other network limit, or the buffer used to receive a datagram into was smaller than the datagram itself.).

panic: runtime error: index out of range [1400] with length 1400

goroutine 54010 [running]:
github.com/rumblefrog/go-a2s.(*PacketReader).ReadString(0xc000487df0, 0xc0004902d0, 0x9)
        /go/src/gocode/vendor/github.com/rumblefrog/go-a2s/packet.go:129 +0xd2
github.com/rumblefrog/go-a2s.(*Client).parsePlayerInfo(0xc00067a000, 0xc001f78580, 0x578, 0x578, 0x0, 0x0, 0x0)
        /go/src/gocode/vendor/github.com/rumblefrog/go-a2s/player.go:131 +0x16b
github.com/rumblefrog/go-a2s.(*Client).QueryPlayer(0xc00067a000, 0xc000dc2280, 0x0, 0x0)
        /go/src/gocode/vendor/github.com/rumblefrog/go-a2s/player.go:94 +0x9e
main.retrieveSource.func1(0xc001e6e060, 0x14, 0xc000487f80, 0xc000487f78, 0xc000487f70, 0x0, 0x0)
        /go/src/gocode/cmd/main/main.go:48 +0x24c
main.retrieveSource(0xc001e6e060, 0x14, 0xc0004980c0)
        /go/src/gocode/cmd/main/main.go:53 +0x86
created by main.queryServers.func1
        /go/src/gocode/cmd/main/main.go:94 +0x524
rumblefrog commented 3 years ago

What game engine is this?

Sir-Will commented 3 years ago

Source, ARK.

Might be because the online players is above the max?

rumblefrog commented 3 years ago

It is possible that Ark deviates from the protocol specification and requires a higher maximum packet size.

I added a client option that allows you to change the maximum size here: https://github.com/rumblefrog/go-a2s/commit/4c67caf251ef40b139ab43a23355a0bf948ccde5

Sir-Will commented 3 years ago

It's not for all ARK server IP's. I queried 2k IP's and this is one of the few which results in the error.

I assume the option just allows bigger packets while smaller ones will still work?

rumblefrog commented 3 years ago

Yes, smaller ones should still work.

And in that scenario, I presume the server modified the a2s player payload, and sent a malformed one; judging from the # of players exceeding maximum players.

Sir-Will commented 3 years ago

Okay, I will try it out, thanks.

Any idea why it causes a runtime error on Ubuntu and not on Windows though? If I query multiple IP's and there is one bad one it will result in no result, as it exits.

rumblefrog commented 3 years ago

It'd have to be the underneath API that golang binds to, that error message is WSAEMSGSIZE 10040 on Windows Winsock, for Linux, it uses a different implementation underneath.

Sir-Will commented 3 years ago

Can this be prevented by checking the length before using the index?

Sir-Will commented 3 years ago

Actually, this will probably work to keep it running? (I'm not experienced in go).

    defer func() {
        if r := recover(); r != nil {
            log.Println("Recovered in source query", r)
        }
    }()
rumblefrog commented 3 years ago

That's what some of the official packages use as try-catch, so yes, it seems right.