Skip to content

Commit 94f72e8

Browse files
authored
Merge pull request #88 from buildbarn/bugfix/logsNullCheck
utf8 encoding for edge cases with build logs
2 parents 19cb077 + 97334f4 commit 94f72e8

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pkg/summary/summarizer.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package summary
22

33
import (
4+
"bytes"
45
"context"
56
"encoding/base64"
67
"errors"
@@ -11,6 +12,7 @@ import (
1112
"strconv"
1213
"strings"
1314
"time"
15+
"unicode/utf8"
1416

1517
"github.com/google/uuid"
1618
"google.golang.org/api/iterator"
@@ -183,13 +185,20 @@ func (s Summarizer) handleBuildProgress(progress *bes.Progress) {
183185
if _, exists := uniqueLines[line]; !exists {
184186
uniqueLines[line] = struct{}{}
185187
if line != "" && line != "\n" {
186-
s.summary.BuildLogs.WriteString(line + "\n")
188+
if utf8.ValidString(line) {
189+
s.summary.BuildLogs.WriteString(sanitizeUTF8(line) + "\n")
190+
}
187191
}
188192
}
189193
}
190194
}
191195
}
192196

197+
func sanitizeUTF8(s string) string {
198+
bs := bytes.ReplaceAll([]byte(s), []byte{0}, []byte{})
199+
return strings.ToValidUTF8(string(bs), "?")
200+
}
201+
193202
// handleStarted
194203
func (s Summarizer) handleStarted(started *bes.BuildStarted) {
195204
var startedAt time.Time

0 commit comments

Comments
 (0)