Skip to content

Commit 680867c

Browse files
committed
benchfmt: return an error in case of a non UTF-8 encoded file
Currently, when using the benchstat tool to read files that are not UTF-8 encoded, it will fail silently. With this patch, when parsing non UTF-8 encoded files, benchfmt will now return an error instead letting the user know their input file is not properly formatted. Fixes golang/go#58579
1 parent f7320a6 commit 680867c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

benchfmt/reader.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ func (r *Reader) Scan() bool {
149149
r.result.line++
150150
// We do everything in byte buffers to avoid allocation.
151151
line := r.s.Bytes()
152+
// We only accept utf-8 encoded files.
153+
if !utf8.Valid(line) {
154+
r.err = fmt.Errorf("%s: invalid encode, only utf-8 encoded files are supported", r.result.fileName)
155+
return false
156+
}
152157
// Most lines are benchmark lines, and we can check
153158
// for that very quickly, so start with that.
154159
if bytes.HasPrefix(line, benchmarkPrefix) {

0 commit comments

Comments
 (0)