Skip to content

Commit

Permalink
syz-manager: truncate repro logs before reporting
Browse files Browse the repository at this point in the history
Until we have figured out a way to solve google#4495, let's just truncate
repro logs before sending them over the dashboard API.
  • Loading branch information
a-nogikh committed Feb 21, 2024
1 parent 3af7dd6 commit ecc726d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 14 deletions.
21 changes: 21 additions & 0 deletions pkg/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,27 @@ func replace(where []byte, start, end int, what []byte) []byte {
return where
}

// Truncate leaves up to `begin` bytes at the beginning of log and
// up to `end` bytes at the end of the log.
func Truncate(log []byte, begin, end int) []byte {
if begin+end >= len(log) {
return log
}
var b bytes.Buffer
b.Write(log[:begin])
if begin > 0 {
b.WriteString("\n\n")
}
fmt.Fprintf(&b, "<<cut %d bytes out>>",
len(log)-begin-end,
)
if end > 0 {
b.WriteString("\n\n")
}
b.Write(log[len(log)-end:])
return b.Bytes()
}

var (
filenameRe = regexp.MustCompile(`([a-zA-Z0-9_\-\./]*[a-zA-Z0-9_\-]+\.(c|h)):[0-9]+`)
reportFrameRe = regexp.MustCompile(`.* in ([a-zA-Z0-9_]+)`)
Expand Down
15 changes: 15 additions & 0 deletions pkg/report/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/google/syzkaller/pkg/report/crash"
"github.com/google/syzkaller/pkg/testutil"
"github.com/google/syzkaller/sys/targets"
"github.com/stretchr/testify/assert"
)

var flagUpdate = flag.Bool("update", false, "update test files accordingly to current results")
Expand Down Expand Up @@ -430,3 +431,17 @@ func TestFuzz(t *testing.T) {
Fuzz([]byte(data)[:len(data):len(data)])
}
}

func TestTruncate(t *testing.T) {
assert.Equal(t, []byte(`01234
<<cut 11 bytes out>>`), Truncate([]byte(`0123456789ABCDEF`), 5, 0))
assert.Equal(t, []byte(`<<cut 11 bytes out>>
BCDEF`), Truncate([]byte(`0123456789ABCDEF`), 0, 5))
assert.Equal(t, []byte(`0123
<<cut 9 bytes out>>
DEF`), Truncate([]byte(`0123456789ABCDEF`), 4, 3))
}
33 changes: 19 additions & 14 deletions syz-manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,12 @@ func (mgr *Manager) needRepro(crash *Crash) bool {
return needRepro
}

func truncateReproLog(log []byte) []byte {
// Repro logs can get quite large and we have trouble sending large API requests (see #4495).
// Let's truncate the log to a 512KB prefix and 512KB suffix.
return report.Truncate(log, 512000, 512000)
}

func (mgr *Manager) saveFailedRepro(rep *report.Report, stats *repro.Stats) {
reproLog := fullReproLog(stats)
if mgr.dash != nil {
Expand All @@ -1051,7 +1057,7 @@ func (mgr *Manager) saveFailedRepro(rep *report.Report, stats *repro.Stats) {
Corrupted: rep.Corrupted,
Suppressed: rep.Suppressed,
MayBeMissing: rep.Type == crash_pkg.MemoryLeak,
ReproLog: reproLog,
ReproLog: truncateReproLog(reproLog),
}
if err := mgr.dash.ReportFailedRepro(cid); err != nil {
log.Logf(0, "failed to report failed repro to dashboard (log size %d): %v",
Expand Down Expand Up @@ -1119,19 +1125,18 @@ func (mgr *Manager) saveRepro(res *ReproResult) {
}

dc := &dashapi.Crash{
BuildID: mgr.cfg.Tag,
Title: report.Title,
AltTitles: report.AltTitles,
Suppressed: report.Suppressed,
Recipients: report.Recipients.ToDash(),
Log: output,
Flags: crashFlags,
Report: report.Report,
ReproOpts: repro.Opts.Serialize(),
ReproSyz: progText,
ReproC: cprogText,
// Paused because of #4495.
// ReproLog: fullReproLog(res.stats),
BuildID: mgr.cfg.Tag,
Title: report.Title,
AltTitles: report.AltTitles,
Suppressed: report.Suppressed,
Recipients: report.Recipients.ToDash(),
Log: output,
Flags: crashFlags,
Report: report.Report,
ReproOpts: repro.Opts.Serialize(),
ReproSyz: progText,
ReproC: cprogText,
ReproLog: truncateReproLog(fullReproLog(res.stats)),
Assets: mgr.uploadReproAssets(repro),
OriginalTitle: res.originalTitle,
}
Expand Down

0 comments on commit ecc726d

Please sign in to comment.