From 69aa7acea306dfd277ec48fcc687ef8fa0f2bdb4 Mon Sep 17 00:00:00 2001 From: hickford Date: Thu, 23 Feb 2023 10:57:05 +0000 Subject: [PATCH 1/2] sumdb/tlog: fuzz tests for parsers Future fuzz tests could test round trip properties Change-Id: If195b82998ebedaeca68a7723c2558369e68f716 GitHub-Last-Rev: 6fff4e678380610ecb5f34e494cec04a9a462f62 GitHub-Pull-Request: golang/mod#18 Reviewed-on: https://go-review.googlesource.com/c/mod/+/470155 Run-TryBot: Matthew Hickford Auto-Submit: Bryan Mills Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Matthew Hickford Run-TryBot: Bryan Mills --- sumdb/tlog/note_test.go | 16 ++++++++++++++++ sumdb/tlog/tile_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 sumdb/tlog/tile_test.go diff --git a/sumdb/tlog/note_test.go b/sumdb/tlog/note_test.go index a32d6d2..3373a0c 100644 --- a/sumdb/tlog/note_test.go +++ b/sumdb/tlog/note_test.go @@ -115,3 +115,19 @@ func TestParseRecord(t *testing.T) { } } } + +// FuzzParseTree tests that ParseTree never crashes +func FuzzParseTree(f *testing.F) { + f.Add([]byte("go.sum database tree\n123456789012\nTszzRgjTG6xce+z2AG31kAXYKBgQVtCSCE40HmuwBb0=\n")) + f.Fuzz(func(t *testing.T, text []byte) { + ParseTree(text) + }) +} + +// FuzzParseRecord tests that ParseRecord never crashes +func FuzzParseRecord(f *testing.F) { + f.Add([]byte("12345\nhello\n\n")) + f.Fuzz(func(t *testing.T, msg []byte) { + ParseRecord(msg) + }) +} diff --git a/sumdb/tlog/tile_test.go b/sumdb/tlog/tile_test.go new file mode 100644 index 0000000..e451a63 --- /dev/null +++ b/sumdb/tlog/tile_test.go @@ -0,0 +1,24 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package tlog + +import ( + "testing" +) + +// FuzzParseTilePath tests that ParseTilePath never crashes +func FuzzParseTilePath(f *testing.F) { + f.Add("tile/4/0/001") + f.Add("tile/4/0/001.p/5") + f.Add("tile/3/5/x123/x456/078") + f.Add("tile/3/5/x123/x456/078.p/2") + f.Add("tile/1/0/x003/x057/500") + f.Add("tile/3/5/123/456/078") + f.Add("tile/3/-1/123/456/078") + f.Add("tile/1/data/x003/x057/500") + f.Fuzz(func(t *testing.T, path string) { + ParseTilePath(path) + }) +} From ad6fd61f94f8fdf6926f5dee6e45bdd13add2f9f Mon Sep 17 00:00:00 2001 From: Heschi Kreinick Date: Wed, 8 Mar 2023 19:46:19 -0500 Subject: [PATCH 2/2] zip: fix on Windows Zip paths are slash-delimited, so using filepath with them is incorrect. Change-Id: I5ad1ee90dea97427b9b291b6fbc52e5bdaf0b678 Reviewed-on: https://go-review.googlesource.com/c/mod/+/474815 TryBot-Result: Gopher Robot Run-TryBot: Heschi Kreinick Auto-Submit: Heschi Kreinick Reviewed-by: Bryan Mills --- zip/zip.go | 2 +- zip/zip_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/zip/zip.go b/zip/zip.go index c5eca4b..7b48a2a 100644 --- a/zip/zip.go +++ b/zip/zip.go @@ -663,7 +663,7 @@ func filesInGitRepo(dir, rev, subdir string) ([]File, error) { if n == "" { continue } - n = strings.TrimPrefix(n, string(filepath.Separator)) + n = strings.TrimPrefix(n, "/") fs = append(fs, zipFile{ name: n, diff --git a/zip/zip_test.go b/zip/zip_test.go index 84a3ecd..173cc65 100644 --- a/zip/zip_test.go +++ b/zip/zip_test.go @@ -1532,7 +1532,7 @@ c/`))) } wantMap := map[string]bool{} for _, f := range tc.wantFiles { - p := filepath.Join("example.com", "foo", "bar@v0.0.1", f) + p := path.Join("example.com", "foo", "bar@v0.0.1", f) wantMap[p] = true }