From 3cedf646952df6e1fd87221d68d13c457eaa3e74 Mon Sep 17 00:00:00 2001 From: Derek Stevens Date: Fri, 3 Feb 2023 17:29:01 -0700 Subject: [PATCH] fix buffer overflow in countlines for files greater than 32kb --- routes/template.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/template.go b/routes/template.go index cf354ca..f56f657 100644 --- a/routes/template.go +++ b/routes/template.go @@ -50,7 +50,7 @@ func countLines(r io.Reader) (int, error) { switch { case err == io.EOF: /* handle last line not having a newline at the end */ - if bufLen >= 1 && buf[bufLen-1] != '\n' { + if bufLen >= 1 && buf[(bufLen-1)%(32*1024)] != '\n' { count++ } return count, nil