Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fuzz: add tendermint/go-amino.DecodeTime #9195

Merged
merged 1 commit into from
Apr 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}()
}
}