|
| 1 | +package packp |
| 2 | + |
| 3 | +import ( |
| 4 | + "bytes" |
| 5 | + "fmt" |
| 6 | + "testing" |
| 7 | +) |
| 8 | + |
| 9 | +func FuzzAdvRefsDecode(f *testing.F) { |
| 10 | + // Minimal well-formed advertisement: a single HEAD ref with one |
| 11 | + // capability followed by a flush packet. Lets the fuzzer mutate |
| 12 | + // from the success path rather than only the error path. |
| 13 | + f.Add([]byte("003b6ecf0ef2c2dffb796033e5a02219af86ec6584e5 HEAD\x00ofs-delta0000")) |
| 14 | + f.Add([]byte{}) |
| 15 | + |
| 16 | + f.Fuzz(func(_ *testing.T, data []byte) { |
| 17 | + ar := &AdvRefs{} |
| 18 | + _ = ar.Decode(bytes.NewReader(data)) |
| 19 | + }) |
| 20 | +} |
| 21 | + |
| 22 | +func FuzzUlReqDecode(f *testing.F) { |
| 23 | + f.Add([]byte("0032want 0000000000000000000000000000000000000000\n0000")) |
| 24 | + f.Add([]byte("0000")) |
| 25 | + f.Add([]byte{}) |
| 26 | + |
| 27 | + f.Fuzz(func(_ *testing.T, data []byte) { |
| 28 | + ur := &UploadRequest{} |
| 29 | + _ = ur.Decode(bytes.NewReader(data)) |
| 30 | + }) |
| 31 | +} |
| 32 | + |
| 33 | +func FuzzUpdReqDecode(f *testing.F) { |
| 34 | + // Minimal well-formed command-and-capabilities frame: a create |
| 35 | + // of refs/heads/main with report-status, followed by a flush. |
| 36 | + // Distinct non-zero hashes are required to pass validation. |
| 37 | + oldHash := "1ecf0ef2c2dffb796033e5a02219af86ec6584e5" |
| 38 | + newHash := "2ecf0ef2c2dffb796033e5a02219af86ec6584e5" |
| 39 | + payload := oldHash + " " + newHash + " refs/heads/main\x00report-status" |
| 40 | + frame := fmt.Sprintf("%04x%s0000", len(payload)+4, payload) |
| 41 | + |
| 42 | + f.Add([]byte(frame)) |
| 43 | + f.Add([]byte("0000")) |
| 44 | + f.Add([]byte{}) |
| 45 | + |
| 46 | + f.Fuzz(func(_ *testing.T, data []byte) { |
| 47 | + ur := &UpdateRequests{} |
| 48 | + _ = ur.Decode(bytes.NewReader(data)) |
| 49 | + }) |
| 50 | +} |
| 51 | + |
| 52 | +func FuzzServerResponseDecode(f *testing.F) { |
| 53 | + f.Add([]byte("0008NAK\n")) |
| 54 | + f.Add([]byte{}) |
| 55 | + |
| 56 | + f.Fuzz(func(_ *testing.T, data []byte) { |
| 57 | + sr := &ServerResponse{} |
| 58 | + _ = sr.Decode(bytes.NewReader(data)) |
| 59 | + }) |
| 60 | +} |
| 61 | + |
| 62 | +func FuzzShallowUpdateDecode(f *testing.F) { |
| 63 | + f.Add([]byte("0034shallow aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0000")) |
| 64 | + f.Add([]byte{}) |
| 65 | + |
| 66 | + f.Fuzz(func(_ *testing.T, data []byte) { |
| 67 | + su := &ShallowUpdate{} |
| 68 | + _ = su.Decode(bytes.NewReader(data)) |
| 69 | + }) |
| 70 | +} |
| 71 | + |
| 72 | +func FuzzReportStatusDecode(f *testing.F) { |
| 73 | + f.Add([]byte("000eunpack ok\n0019ok refs/heads/master\n0000")) |
| 74 | + f.Add([]byte{}) |
| 75 | + |
| 76 | + f.Fuzz(func(_ *testing.T, data []byte) { |
| 77 | + rs := &ReportStatus{} |
| 78 | + _ = rs.Decode(bytes.NewReader(data)) |
| 79 | + }) |
| 80 | +} |
| 81 | + |
| 82 | +func FuzzGitProtoDecode(f *testing.F) { |
| 83 | + f.Add([]byte("002ecommand pathname\x00host=host\x00\x00param1\x00param2\x00")) |
| 84 | + f.Add([]byte{}) |
| 85 | + |
| 86 | + f.Fuzz(func(_ *testing.T, data []byte) { |
| 87 | + gp := &GitProtoRequest{} |
| 88 | + _ = gp.Decode(bytes.NewReader(data)) |
| 89 | + }) |
| 90 | +} |
| 91 | + |
| 92 | +func FuzzPushOptionsDecode(f *testing.F) { |
| 93 | + f.Add([]byte("0015SomeKey=SomeValue0000")) |
| 94 | + f.Add([]byte{}) |
| 95 | + |
| 96 | + f.Fuzz(func(_ *testing.T, data []byte) { |
| 97 | + po := &PushOptions{} |
| 98 | + _ = po.Decode(bytes.NewReader(data)) |
| 99 | + }) |
| 100 | +} |
0 commit comments