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

If a player is not in the server (he left the game), the parser crashes #455

Open
noxterr opened this issue Oct 23, 2023 · 0 comments
Open

Comments

@noxterr
Copy link

noxterr commented Oct 23, 2023

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

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

No branches or pull requests

2 participants