Skip to content

Commit

Permalink
fuzz: add types.{FormatTimeBytes, ParseTimeBytes}
Browse files Browse the repository at this point in the history
Updates #7921.
  • Loading branch information
odeke-em committed Apr 22, 2021
1 parent 859327e commit 5d451c1
Show file tree
Hide file tree
Showing 57 changed files with 117 additions and 0 deletions.
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/1.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1964-01-18T14:37:47.320621000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/10.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1997-09-04T03:37:47.322164000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/11.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1974-01-06T17:37:47.322320000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/12.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1989-02-04T08:37:47.322476000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/13.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2006-03-31T21:37:47.322634000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/14.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1968-12-13T22:37:47.322780000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/15.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2018-01-17T15:37:47.322928000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/16.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1971-06-10T21:37:47.323131000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/17.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1985-05-13T20:37:47.323333000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/18.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1971-08-26T02:37:47.323508000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/19.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1983-12-29T18:37:47.323678000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/2.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1994-11-14T16:37:47.320923000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/20.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1982-03-08T13:37:47.323838000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/21.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1982-01-09T16:37:47.324041000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/22.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1967-10-08T13:37:47.324195000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/23.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2019-07-21T15:37:47.325930000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/24.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1999-08-15T05:37:47.326461000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/25.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1968-08-12T16:37:47.326648000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/26.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1966-02-12T04:37:47.326837000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/27.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2005-02-03T00:37:47.327052000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/28.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2005-09-15T23:37:47.327218000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/29.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1987-06-20T09:37:47.327376000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/3.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2005-10-29T08:37:47.321082000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/30.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1998-11-06T16:37:47.327530000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/31.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1975-09-30T02:37:47.327676000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/32.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1988-11-17T07:37:47.327828000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/33.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2020-01-10T04:37:47.327976000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/34.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2013-03-30T08:37:47.328196000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/35.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1984-11-19T02:37:47.328368000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/36.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2006-07-26T19:37:47.328529000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/37.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1981-11-18T22:37:47.328693000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/38.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1968-04-27T00:37:47.328847000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/39.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2008-02-24T18:37:47.328990000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/4.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1965-08-24T20:37:47.321229000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/40.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2019-02-25T21:37:47.329141000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/41.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2011-01-04T10:37:47.329283000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/42.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2020-07-07T05:37:47.331981000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/43.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2013-06-06T13:37:47.332191000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/44.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2010-07-15T12:37:47.332326000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/45.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1996-08-19T14:37:47.332485000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/46.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1972-06-25T04:37:47.332655000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/47.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1966-10-14T17:37:47.332794000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/48.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1990-09-18T11:37:47.332923000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/49.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2019-01-09T16:37:47.333094000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/5.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1974-12-31T14:37:47.321383000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/50.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1967-02-05T06:37:47.333358000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/6.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1970-07-10T17:37:47.321532000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/7.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1969-01-10T14:37:47.321683000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/8.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2006-11-21T03:37:47.321837000
1 change: 1 addition & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/corpus/9.seed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1993-06-08T23:37:47.321985000
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0000-07-06T0:00:00.000000000
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
panic: Roundtrip failure, got
0000-07-06T00:00:00.000000000

goroutine 1 [running]:
github.com/cosmos/cosmos-sdk/fuzz/types/ParseTimeBytes.Fuzz(0xaa70000, 0x1c, 0x1c, 0x4)
/Users/emmanuelodeke/go/src/github.com/cosmos/cosmos-sdk/fuzz/types/ParseTimeBytes/fuzz.go:17 +0x265
go-fuzz-dep.Main(0xc000271f70, 0x1, 0x1)
go-fuzz-dep/main.go:36 +0x1b8
main.main()
github.com/cosmos/cosmos-sdk/fuzz/types/ParseTimeBytes/go.fuzz.main/main.go:15 +0x52
exit status 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"0000-07-06T0:00:00.0" +
"00000000"
23 changes: 23 additions & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/fuzz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package parsetimebytes

import (
"bytes"
"fmt"

"github.com/cosmos/cosmos-sdk/types"
)

func Fuzz(bin []byte) int {
t, err := types.ParseTimeBytes(bin)
if err != nil {
return -1
}
brt := types.FormatTimeBytes(t)
if !bytes.Equal(brt, bin) {
panic(fmt.Sprintf("Roundtrip failure, got\n%s", brt))
}

// Parsed successfully, indicate to the fuzzer that it should increase
// the priority of this input, thus make it a part of the corpus.
return 1
}
26 changes: 26 additions & 0 deletions fuzz/types/ParseTimeBytesFormatTimeBytes/generate/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"fmt"
"math/rand"
"os"
"time"

"github.com/cosmos/cosmos-sdk/types"
)

func main() {
for i := 0; i < 50; i++ {
func() {
f, err := os.Create(fmt.Sprintf("corpus/%d.seed", i+1))
if err != nil {
return
}
defer f.Close()
rnd := rand.Intn(500000)
ti := time.Now().Add(time.Duration(-rnd) * time.Hour)
b := types.FormatTimeBytes(ti)
f.Write(b)
}()
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
panic: Roundtrip failure, got
github.com/cosmos/cosmos-sdk/fuzz/types/ParseTimeBytes.Fuzz
go-fuzz-dep.Main
main.main

0 comments on commit 5d451c1

Please sign in to comment.