demoinfocs-golang
demoinfocs-golang copied to clipboard
If a player is not in the server (he left the game), the parser crashes
I was parsing some demos in order to gather certain data from the player, but after 10 rounds, the parser crashed with invalid memory address or nil pointer dereference. I checked and I saw there was a leaver in the game. My thought is that the player is parsed from the start, and when he leaves, he's not removed and still the parser tries to access data from him. Because he left, there is nothing to check, the player is nil, and the parser crashes
To Reproduce Download the demo at this matchroom link, which contains the leaver player (the zipped demo file is here) and run the code below with the demo in place
Code:
package main
import (
"fmt"
"log"
"os"
dem "github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs"
events "github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs/events"
)
func main() {
f, err := os.Open("/path/to/demo.dem")
if err != nil {
log.Panic("failed to open demo file: ", err)
}
defer f.Close()
p := dem.NewParser(f)
defer p.Close()
// Register handler on kill events
p.RegisterEventHandler(func(e events.Kill) {
fmt.Printf("%s <%v> %s\n", e.Killer, e.Weapon, e.Victim)
})
// Parse to end
err = p.ParseToEnd()
if err != nil {
log.Panic("failed to parse demo: ", err)
}
}
Expected behavior
I could expect the parser to ignore the missing player and not show him from the moment he's not on the server anymore. However, this is not the case and it crashes. I am not really able to troubleshoot the error myself, but I'd start at pkg/demoinfocs/datatables.go:116 which is where the error logs show something
Library version The library is at version V4
Additional context Running Windows 10 and Go 1.21.3