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

HTTP Body io.Reader as parser input results in ErrUnexpectedEndOfDemo #299

Closed
martig3 opened this issue Jun 11, 2021 · 6 comments
Closed

Comments

@martig3
Copy link

martig3 commented Jun 11, 2021

Describe the bug
Passing an HTTP Body io.Reader to NewParser() then calling ParseToEnd() results in an demo stream ended unexpectedly (ErrUnexpectedEndOfDemo) error

To Reproduce
I tested with https://www.dropbox.com/s/7lb1r11olhc6a1b/2021-6-6_pug_de_overpass_60bc5197ffc453a0de48212d.dem?dl=0 but I believe this is reproducible with all demos.

Code:

package main

import (
	"github.com/gin-gonic/gin"
	"github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs"
)

func main() {
	r := gin.Default()
	r.POST("/parse-stats", func(c *gin.Context) {
		p := demoinfocs.NewParser(c.Request.Body)
		err := p.ParseToEnd()
		if err != nil {
			c.AbortWithStatusJSON(500, err.Error())
			return
		}
               c.JSON(200, "success")
	})
	err := r.Run()
	if err != nil {
		println(err)
		return
	} // listen and serve on 0.0.0.0:8080
}

Expected behavior
Demo gets parsed successfully as it does with os.Open() readers. Specifically from the code example, POSTing to /parse-stats should return a 200 and not panic on p.ParseToEnd().

Library version
v2.9.0

@markus-wa
Copy link
Owner

Thanks for raising this, I will probably need to fix something in https://github.com/markus-wa/gobitread 😅

@markus-wa
Copy link
Owner

markus-wa commented Jun 15, 2021

ah, for anyone else who finds this (as discussed via gitter):
the workaround for now is to use io.ReadAll() and then creating a bytes.NewReader() on top of the returned byte array

@markus-wa
Copy link
Owner

sorry this took so long @martig3 , would you be able to try with this branch: #305

go get -u github.com/markus-wa/demoinfocs-golang/v2@fix-bitread-streaming

I'm not 100% sure it will fix every case but for me I had a similar issue with gzip that went away with the change.
Would be great if you can test it with Gin as I don't have the setup (i.e. curl command or so) to then upload a demo via post at hand

@martig3
Copy link
Author

martig3 commented Jul 13, 2021

No problem @markus-wa, thanks for the patch. I tested this with a few of my demo files and it appears to be working in my project branch here. When I have some more time I'll write some tests on my end but it appears to be working consistently enough for me at the moment.

@markus-wa
Copy link
Owner

awesome, thanks - I'll get a release out later this week

@markus-wa
Copy link
Owner

Just released v2.10.0 which should fix it.

I'm not 100% sure if this will cover all cases as it's a bit tricky to test - but if anyone is still experiencing issues please let me know and we can re-open this 🙂

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