rumblefrog / go-a2s

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

Index out of range error #8

Closed justinnobledev closed 1 year ago

justinnobledev commented 2 years ago

Hi, I'm in the process of building a server tracking website and need to iterate over a lot of servers so I can't give a specific server as an example of which game/server is causing this error,. but every time I run it pretty early into its execution I encounter one of these two index out of range errors. The games I'm currently trying to use this on before expanding to other games is CSGO, TF2, Garry's Mod.

When it fails to convert bytes to uint

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

goroutine 259 [running]:
encoding/binary.littleEndian.Uint32(...)
        C:/Program Files/Go/src/encoding/binary/binary.go:64
github.com/rumblefrog/go-a2s.(*PacketReader).ReadUint32(...)
        C:/Users/Justin/go/pkg/mod/github.com/rumblefrog/go-a2s@v1.0.1/packet.go:89
github.com/rumblefrog/go-a2s.(*PacketReader).ReadFloat32(...)
        C:/Users/Justin/go/pkg/mod/github.com/rumblefrog/go-a2s@v1.0.1/packet.go:105
github.com/rumblefrog/go-a2s.(*Client).parsePlayerInfo(0xc00060e930, {0xc001bc96e0, 0x105, 0xc000020680})
        C:/Users/Justin/go/pkg/mod/github.com/rumblefrog/go-a2s@v1.0.1/player.go:134 +0x487
github.com/rumblefrog/go-a2s.(*Client).QueryPlayer(0xc00041eab0)
        C:/Users/Justin/go/pkg/mod/github.com/rumblefrog/go-a2s@v1.0.1/player.go:95 +0x138
main.main.func2({{0xc000a6ae80, 0x10}, 0x6987, {0xc00060c5a0, 0x2f}, 0x2da, {0xc000a6aea8, 0x4}, {0xc000a6af40, 0x8}, ...})
        C:/Code/go/server-query/main.go:119 +0x4bc
created by main.main
        C:/Code/go/server-query/main.go:102 +0x345
exit status 2
panic: runtime error: index out of range [1260] with length 1260

goroutine 1677 [running]:
github.com/rumblefrog/go-a2s.(*PacketReader).ReadString(...)
        C:/Users/Justin/go/pkg/mod/github.com/rumblefrog/go-a2s@v1.0.1/packet.go:125
github.com/rumblefrog/go-a2s.(*Client).parsePlayerInfo(0xc000cff1f0, {0xc001246a00, 0x9, 0x9})
        C:/Users/Justin/go/pkg/mod/github.com/rumblefrog/go-a2s@v1.0.1/player.go:132 +0x4b6
github.com/rumblefrog/go-a2s.(*Client).QueryPlayer(0xc0012cd5c0)
        C:/Users/Justin/go/pkg/mod/github.com/rumblefrog/go-a2s@v1.0.1/player.go:95 +0x138
main.main.func2({{0xc000c1edb0, 0x15}, 0x6987, {0xc0005bdf24, 0xb}, 0xfa0, {0xc0005bde97, 0x9}, {0xc0005bdf80, 0xa}, ...})
        C:/Code/go/server-query/main.go:119 +0x4bc
created by main.main
        C:/Code/go/server-query/main.go:102 +0x3f3
exit status 2
justinnobledev commented 2 years ago

Just to give a little bit of an update, the 1st one seems to be related to csgo and the 2nd one seems to be related to gmod.

mpawlowski commented 2 years ago

Apparently CS:GO servers by default return only max players and server uptime from a note in the A2S documentation, which makes sense why its failing on parsing a name.

A server cvar can also change the format of the response, which is problematic since the client doesn't know which fields to parse.

therileycloud commented 1 year ago

Same issue with rust server, it's bizarre because it did work initially, then stopped after a while and threw up this ever since.

Serving metrics at http://127.0.0.1:9841/metrics

panic: runtime error: index out of range [3] with length 1
goroutine 6 [running]:
encoding/binary.littleEndian.Uint32(...)
        /usr/local/go/src/encoding/binary/binary.go:80
github.com/rumblefrog/go-a2s.(*PacketReader).ReadUint32(...)
        /go/pkg/mod/github.com/rumblefrog/go-a2s@v1.0.1/packet.go:89
github.com/rumblefrog/go-a2s.(*Client).parsePlayerInfo(0xc00017aa80, {0xc0001a0580?, 0x9?, 0x9?})
        /go/pkg/mod/github.com/rumblefrog/go-a2s@v1.0.1/player.go:133 +0x4af
github.com/rumblefrog/go-a2s.(*Client).QueryPlayer(0x7ffc68301f73?)
        /go/pkg/mod/github.com/rumblefrog/go-a2s@v1.0.1/player.go:95 +0x138
github.com/armsnyder/a2s-exporter/internal/collector.(*Collector).queryInfo(0xc0000c0860)
        /build/internal/collector/collector.go:128 +0x2a5
github.com/armsnyder/a2s-exporter/internal/collector.(*Collector).Collect(0xc0000c0860, 0xc000060120)
        /build/internal/collector/collector.go:68 +0x2d
github.com/prometheus/client_golang/prometheus.(*Registry).Gather.func1()
        /go/pkg/mod/github.com/prometheus/client_golang@v1.14.0/prometheus/registry.go:456 +0x10d
created by github.com/prometheus/client_golang/prometheus.(*Registry).Gather
        /go/pkg/mod/github.com/prometheus/client_golang@v1.14.0/prometheus/registry.go:467 +0x55d
rumblefrog commented 1 year ago

@justinnobledev If you could try it with the latest?

justinnobledev commented 1 year ago

This doesn't seem to be panicking anymore for me!