fix buffer overflow in countlines for files greater than 32kb

This commit is contained in:
Iris Lightshard 2023-02-03 17:29:01 -07:00
parent 8eea0d5bbc
commit 3cedf64695
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398

View file

@ -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