go-a2s icon indicating copy to clipboard operation
go-a2s copied to clipboard

Index out of range error

Open justinnobledev opened this issue 2 years ago • 1 comments

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/[email protected]/packet.go:89
github.com/rumblefrog/go-a2s.(*PacketReader).ReadFloat32(...)
        C:/Users/Justin/go/pkg/mod/github.com/rumblefrog/[email protected]/packet.go:105
github.com/rumblefrog/go-a2s.(*Client).parsePlayerInfo(0xc00060e930, {0xc001bc96e0, 0x105, 0xc000020680})
        C:/Users/Justin/go/pkg/mod/github.com/rumblefrog/[email protected]/player.go:134 +0x487
github.com/rumblefrog/go-a2s.(*Client).QueryPlayer(0xc00041eab0)
        C:/Users/Justin/go/pkg/mod/github.com/rumblefrog/[email protected]/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/[email protected]/packet.go:125
github.com/rumblefrog/go-a2s.(*Client).parsePlayerInfo(0xc000cff1f0, {0xc001246a00, 0x9, 0x9})
        C:/Users/Justin/go/pkg/mod/github.com/rumblefrog/[email protected]/player.go:132 +0x4b6
github.com/rumblefrog/go-a2s.(*Client).QueryPlayer(0xc0012cd5c0)
        C:/Users/Justin/go/pkg/mod/github.com/rumblefrog/[email protected]/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 avatar Oct 19 '22 22:10 justinnobledev

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.

justinnobledev avatar Oct 25 '22 22:10 justinnobledev

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.

mpawlowski avatar Nov 01 '22 20:11 mpawlowski

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/[email protected]/packet.go:89
github.com/rumblefrog/go-a2s.(*Client).parsePlayerInfo(0xc00017aa80, {0xc0001a0580?, 0x9?, 0x9?})
        /go/pkg/mod/github.com/rumblefrog/[email protected]/player.go:133 +0x4af
github.com/rumblefrog/go-a2s.(*Client).QueryPlayer(0x7ffc68301f73?)
        /go/pkg/mod/github.com/rumblefrog/[email protected]/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/[email protected]/prometheus/registry.go:456 +0x10d
created by github.com/prometheus/client_golang/prometheus.(*Registry).Gather
        /go/pkg/mod/github.com/prometheus/[email protected]/prometheus/registry.go:467 +0x55d

therileycloud avatar Dec 10 '22 12:12 therileycloud

@justinnobledev If you could try it with the latest?

rumblefrog avatar Dec 13 '22 01:12 rumblefrog

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

justinnobledev avatar Dec 17 '22 01:12 justinnobledev