Skip to content

Commit

Permalink
fuzz: add tendermint/go-amino.DecodeTime (cosmos#9195)
Browse files Browse the repository at this point in the history
go-amino is a heavily used dependency and given that
Tendermrint isn't yet setup for oss-fuzz, this change
is a start for it.

While here, add the oss-fuzz entry for crypto/types.BitArray
CompactUnmarshal fuzzer for PR cosmos#9166.

Updates cosmos#7921
  • Loading branch information
odeke-em authored and elias-orijtech committed Apr 11, 2022
1 parent 29e8990 commit 4c426df
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 0 deletions.
4 changes: 4 additions & 0 deletions fuzz/oss-fuzz-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export FUZZ_ROOT="github.com/cosmos/cosmos-sdk"

compile_go_fuzzer "$FUZZ_ROOT"/fuzz/crypto/hd/deriveprivatekeyforpath Fuzz fuzz_crypto_hd_deriveprivatekeyforpath fuzz

compile_go_fuzzer "$FUZZ_ROOT"/fuzz/crypto/types/compactbitarray/marshalunmarshal Fuzz fuzz_crypto_types_compactbitarray_marshalunmarshal fuzz

compile_go_fuzzer "$FUZZ_ROOT"/fuzz/tendermint/amino/decodetime Fuzz fuzz_tendermint_amino_decodetime fuzz

compile_go_fuzzer "$FUZZ_ROOT"/fuzz/types/parsecoin Fuzz fuzz_types_parsecoin fuzz
compile_go_fuzzer "$FUZZ_ROOT"/fuzz/types/parsedeccoin Fuzz fuzz_types_parsedeccoin fuzz
compile_go_fuzzer "$FUZZ_ROOT"/fuzz/types/parsetimebytes Fuzz fuzz_types_parsetimebytes fuzz
Expand Down
Empty file.
1 change: 1 addition & 0 deletions fuzz/tendermint/amino/DecodeTime/corpus/2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
������
1 change: 1 addition & 0 deletions fuzz/tendermint/amino/DecodeTime/corpus/3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
����؝�
1 change: 1 addition & 0 deletions fuzz/tendermint/amino/DecodeTime/corpus/4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�墕𓝚
1 change: 1 addition & 0 deletions fuzz/tendermint/amino/DecodeTime/corpus/5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
����𓝚
1 change: 1 addition & 0 deletions fuzz/tendermint/amino/DecodeTime/corpus/6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
����𓝚
1 change: 1 addition & 0 deletions fuzz/tendermint/amino/DecodeTime/corpus/7.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
����𓝚
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

24 changes: 24 additions & 0 deletions fuzz/tendermint/amino/DecodeTime/fuzz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package decodetime

import (
"fmt"

amino "github.com/tendermint/go-amino"
)

func Fuzz(data []byte) int {
if len(data) == 0 {
return -1
}
t, n, err := amino.DecodeTime(data)
if err != nil {
return -1
}
if n < 0 {
panic(fmt.Sprintf("n=%d < 0", n))
}
if t.IsZero() {
return 0
}
return 1
}
35 changes: 35 additions & 0 deletions fuzz/tendermint/amino/DecodeTime/gen/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"fmt"
"os"
"time"

amino "github.com/tendermint/go-amino"
)

func main() {
times := []time.Time{
time.Unix(0, 0),
time.Now(),
time.Date(1979, time.January, 02, 10, 11, 12, 7999192, time.UTC),
time.Now().Add(10000 * time.Hour),
time.Now().Add(100 * time.Hour),
time.Now().Add(-100 * time.Hour),
time.Now().Add(-10000 * time.Hour),
}

for i, t := range times {
func() {
f, err := os.Create(fmt.Sprintf("%d.txt", i+1))
if err != nil {
panic(err)
}
defer f.Close()

if err := amino.EncodeTime(f, t); err != nil {
panic(err)
}
}()
}
}

0 comments on commit 4c426df

Please sign in to comment.