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

export seed corpus files using the SHA1 of the content as the filename #2731

Merged
merged 4 commits into from
Aug 25, 2020
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: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,3 @@ fuzzing/*/crashers
fuzzing/*/sonarprofile
fuzzing/*/suppressions
fuzzing/*/corpus/
fuzzing/*-fuzz.zip
!fuzzing/frames/single-frame*
!fuzzing/frames/multiple-frame*
!fuzzing/header/header*
34 changes: 10 additions & 24 deletions fuzzing/frames/cmd/corpus.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package main

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

"github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/fuzzing/internal/helper"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/qerr"
"github.com/lucas-clemente/quic-go/internal/wire"
Expand Down Expand Up @@ -246,19 +246,17 @@ func getFrames() []wire.Frame {
}

func main() {
rand.Seed(42)

for i, f := range getFrames() {
for _, f := range getFrames() {
b := &bytes.Buffer{}
if err := f.Write(b, version); err != nil {
panic(err)
log.Fatal(err)
}
if err := writeCorpusFile(fmt.Sprintf("single-frame-%d", i), b.Bytes()); err != nil {
panic(err)
if err := helper.WriteCorpusFileWithPrefix("corpus", b.Bytes(), 1); err != nil {
log.Fatal(err)
}
}

for i := 0; i < 25; i++ {
for i := 0; i < 30; i++ {
frames := getFrames()

b := &bytes.Buffer{}
Expand All @@ -268,26 +266,14 @@ func main() {
}
f := frames[rand.Intn(len(frames))]
if err := f.Write(b, version); err != nil {
panic(err)
log.Fatal(err)
}
if rand.Intn(10) == 0 { // write a PADDING frame
b.WriteByte(0x0)
}
}
if err := writeCorpusFile(fmt.Sprintf("multiple-frames-%d", i), b.Bytes()); err != nil {
panic(err)
if err := helper.WriteCorpusFileWithPrefix("corpus", b.Bytes(), 1); err != nil {
log.Fatal(err)
}
}
}

func writeCorpusFile(name string, data []byte) error {
file, err := os.Create("corpus/" + name)
if err != nil {
return err
}
data = append(getRandomData(1), data...)
if _, err := file.Write(data); err != nil {
return err
}
return file.Close()
}
Binary file removed fuzzing/frames/corpus/multiple-frames-0
Binary file not shown.
Binary file removed fuzzing/frames/corpus/multiple-frames-1
Binary file not shown.
Binary file removed fuzzing/frames/corpus/multiple-frames-10
Binary file not shown.
Binary file removed fuzzing/frames/corpus/multiple-frames-11
Binary file not shown.
Binary file removed fuzzing/frames/corpus/multiple-frames-12
Binary file not shown.
Binary file removed fuzzing/frames/corpus/multiple-frames-13
Binary file not shown.
Binary file removed fuzzing/frames/corpus/multiple-frames-14
Binary file not shown.
Binary file removed fuzzing/frames/corpus/multiple-frames-15
Binary file not shown.
Binary file removed fuzzing/frames/corpus/multiple-frames-16
Binary file not shown.
Binary file removed fuzzing/frames/corpus/multiple-frames-17
Binary file not shown.
Binary file removed fuzzing/frames/corpus/multiple-frames-18
Binary file not shown.
Binary file removed fuzzing/frames/corpus/multiple-frames-19
Binary file not shown.
Binary file removed fuzzing/frames/corpus/multiple-frames-2
Binary file not shown.
Binary file removed fuzzing/frames/corpus/multiple-frames-20
Binary file not shown.
Binary file removed fuzzing/frames/corpus/multiple-frames-21
Binary file not shown.
Binary file removed fuzzing/frames/corpus/multiple-frames-22
Binary file not shown.
Binary file removed fuzzing/frames/corpus/multiple-frames-23
Binary file not shown.
Binary file removed fuzzing/frames/corpus/multiple-frames-24
Binary file not shown.
Binary file removed fuzzing/frames/corpus/multiple-frames-3
Binary file not shown.
Binary file removed fuzzing/frames/corpus/multiple-frames-4
Binary file not shown.
Binary file removed fuzzing/frames/corpus/multiple-frames-5
Binary file not shown.
Binary file removed fuzzing/frames/corpus/multiple-frames-6
Binary file not shown.
Binary file removed fuzzing/frames/corpus/multiple-frames-7
Binary file not shown.
Binary file removed fuzzing/frames/corpus/multiple-frames-8
Binary file not shown.
Binary file removed fuzzing/frames/corpus/multiple-frames-9
Binary file not shown.
1 change: 0 additions & 1 deletion fuzzing/frames/corpus/single-frame-0

This file was deleted.

1 change: 0 additions & 1 deletion fuzzing/frames/corpus/single-frame-1

This file was deleted.

1 change: 0 additions & 1 deletion fuzzing/frames/corpus/single-frame-10

This file was deleted.

1 change: 0 additions & 1 deletion fuzzing/frames/corpus/single-frame-11

This file was deleted.

1 change: 0 additions & 1 deletion fuzzing/frames/corpus/single-frame-12

This file was deleted.

Binary file removed fuzzing/frames/corpus/single-frame-13
Binary file not shown.
Binary file removed fuzzing/frames/corpus/single-frame-14
Binary file not shown.
Binary file removed fuzzing/frames/corpus/single-frame-15
Binary file not shown.
2 changes: 0 additions & 2 deletions fuzzing/frames/corpus/single-frame-16

This file was deleted.

1 change: 0 additions & 1 deletion fuzzing/frames/corpus/single-frame-17

This file was deleted.

1 change: 0 additions & 1 deletion fuzzing/frames/corpus/single-frame-18

This file was deleted.

1 change: 0 additions & 1 deletion fuzzing/frames/corpus/single-frame-19

This file was deleted.

Binary file removed fuzzing/frames/corpus/single-frame-2
Binary file not shown.
1 change: 0 additions & 1 deletion fuzzing/frames/corpus/single-frame-20

This file was deleted.

1 change: 0 additions & 1 deletion fuzzing/frames/corpus/single-frame-21

This file was deleted.

1 change: 0 additions & 1 deletion fuzzing/frames/corpus/single-frame-22

This file was deleted.

1 change: 0 additions & 1 deletion fuzzing/frames/corpus/single-frame-23

This file was deleted.

1 change: 0 additions & 1 deletion fuzzing/frames/corpus/single-frame-24

This file was deleted.

1 change: 0 additions & 1 deletion fuzzing/frames/corpus/single-frame-25

This file was deleted.

1 change: 0 additions & 1 deletion fuzzing/frames/corpus/single-frame-26

This file was deleted.

1 change: 0 additions & 1 deletion fuzzing/frames/corpus/single-frame-27

This file was deleted.

1 change: 0 additions & 1 deletion fuzzing/frames/corpus/single-frame-28

This file was deleted.

1 change: 0 additions & 1 deletion fuzzing/frames/corpus/single-frame-29

This file was deleted.

1 change: 0 additions & 1 deletion fuzzing/frames/corpus/single-frame-3

This file was deleted.

Binary file removed fuzzing/frames/corpus/single-frame-30
Binary file not shown.
Binary file removed fuzzing/frames/corpus/single-frame-31
Binary file not shown.
Binary file removed fuzzing/frames/corpus/single-frame-32
Binary file not shown.
1 change: 0 additions & 1 deletion fuzzing/frames/corpus/single-frame-33

This file was deleted.

1 change: 0 additions & 1 deletion fuzzing/frames/corpus/single-frame-34

This file was deleted.

3 changes: 0 additions & 3 deletions fuzzing/frames/corpus/single-frame-35

This file was deleted.

Binary file removed fuzzing/frames/corpus/single-frame-36
Binary file not shown.
2 changes: 0 additions & 2 deletions fuzzing/frames/corpus/single-frame-4

This file was deleted.

1 change: 0 additions & 1 deletion fuzzing/frames/corpus/single-frame-5

This file was deleted.

1 change: 0 additions & 1 deletion fuzzing/frames/corpus/single-frame-6

This file was deleted.

Binary file removed fuzzing/frames/corpus/single-frame-7
Binary file not shown.
1 change: 0 additions & 1 deletion fuzzing/frames/corpus/single-frame-8

This file was deleted.

Binary file removed fuzzing/frames/corpus/single-frame-9
Binary file not shown.
35 changes: 21 additions & 14 deletions fuzzing/frames/fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,34 @@ import (
"github.com/lucas-clemente/quic-go/internal/wire"
)

const version = protocol.VersionTLS

// PrefixLen is the number of bytes used for configuration
const PrefixLen = 1

func toEncLevel(v uint8) protocol.EncryptionLevel {
switch v % 3 {
default:
return protocol.EncryptionInitial
case 1:
return protocol.EncryptionHandshake
case 2:
return protocol.Encryption1RTT
}
}

// Fuzz fuzzes the QUIC frames.
//go:generate go run ./cmd/corpus.go
func Fuzz(data []byte) int {
const version = protocol.VersionTLS

if len(data) < 1 {
if len(data) < PrefixLen {
return 0
}
encLevel := toEncLevel(data[0])
data = data[PrefixLen:]

parser := wire.NewFrameParser(version)
parser.SetAckDelayExponent(protocol.DefaultAckDelayExponent)

var encLevel protocol.EncryptionLevel
switch data[0] % 3 {
case 0:
encLevel = protocol.EncryptionInitial
case 1:
encLevel = protocol.EncryptionHandshake
case 2:
encLevel = protocol.Encryption1RTT
}

data = data[1:]
r := bytes.NewReader(data)
initialLen := r.Len()

Expand Down
52 changes: 19 additions & 33 deletions fuzzing/header/cmd/corpus.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package main

import (
"bytes"
"fmt"
"log"
"math/rand"
"os"

"github.com/lucas-clemente/quic-go/fuzzing/header"
"github.com/lucas-clemente/quic-go/fuzzing/internal/helper"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/wire"
)
Expand All @@ -25,31 +26,29 @@ func getVNP(src, dest protocol.ConnectionID, numVersions int) []byte {
}
data, err := wire.ComposeVersionNegotiation(src, dest, versions)
if err != nil {
panic(err)
log.Fatal(err)
}
return data
}

func main() {
rand.Seed(1337)

headers := []wire.Header{
wire.Header{ // Initial without token
{ // Initial without token
IsLongHeader: true,
SrcConnectionID: protocol.ConnectionID(getRandomData(3)),
DestConnectionID: protocol.ConnectionID(getRandomData(8)),
Type: protocol.PacketTypeInitial,
Length: protocol.ByteCount(rand.Intn(1000)),
Version: version,
},
wire.Header{ // Initial without token, with zero-length src conn id
{ // Initial without token, with zero-length src conn id
IsLongHeader: true,
DestConnectionID: protocol.ConnectionID(getRandomData(8)),
Type: protocol.PacketTypeInitial,
Length: protocol.ByteCount(rand.Intn(1000)),
Version: version,
},
wire.Header{ // Initial with Token
{ // Initial with Token
IsLongHeader: true,
SrcConnectionID: protocol.ConnectionID(getRandomData(10)),
DestConnectionID: protocol.ConnectionID(getRandomData(19)),
Expand All @@ -58,51 +57,51 @@ func main() {
Version: version,
Token: getRandomData(25),
},
wire.Header{ // Handshake packet
{ // Handshake packet
IsLongHeader: true,
SrcConnectionID: protocol.ConnectionID(getRandomData(5)),
DestConnectionID: protocol.ConnectionID(getRandomData(10)),
Type: protocol.PacketTypeHandshake,
Length: protocol.ByteCount(rand.Intn(1000)),
Version: version,
},
wire.Header{ // Handshake packet, with zero-length src conn id
{ // Handshake packet, with zero-length src conn id
IsLongHeader: true,
DestConnectionID: protocol.ConnectionID(getRandomData(12)),
Type: protocol.PacketTypeHandshake,
Length: protocol.ByteCount(rand.Intn(1000)),
Version: version,
},
wire.Header{ // 0-RTT packet
{ // 0-RTT packet
IsLongHeader: true,
SrcConnectionID: protocol.ConnectionID(getRandomData(8)),
DestConnectionID: protocol.ConnectionID(getRandomData(9)),
Type: protocol.PacketType0RTT,
Length: protocol.ByteCount(rand.Intn(1000)),
Version: version,
},
wire.Header{ // Retry Packet, with empty orig dest conn id
{ // Retry Packet, with empty orig dest conn id
IsLongHeader: true,
SrcConnectionID: protocol.ConnectionID(getRandomData(8)),
DestConnectionID: protocol.ConnectionID(getRandomData(9)),
Type: protocol.PacketTypeRetry,
Token: getRandomData(1000),
Version: version,
},
wire.Header{ // Short-Header
{ // Short-Header
DestConnectionID: protocol.ConnectionID(getRandomData(8)),
},
}

for i, h := range headers {
for _, h := range headers {
extHdr := &wire.ExtendedHeader{
Header: h,
PacketNumberLen: protocol.PacketNumberLen(rand.Intn(4) + 1),
PacketNumber: protocol.PacketNumber(rand.Uint64()),
}
b := &bytes.Buffer{}
if err := extHdr.Write(b, version); err != nil {
panic(err)
log.Fatal(err)
}
if h.Type == protocol.PacketTypeRetry {
b.Write([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16})
Expand All @@ -111,8 +110,8 @@ func main() {
b.Write(make([]byte, h.Length))
}

if err := writeCorpusFile(fmt.Sprintf("header-%d", i), b.Bytes()); err != nil {
panic(err)
if err := helper.WriteCorpusFileWithPrefix("corpus", b.Bytes(), header.PrefixLen); err != nil {
log.Fatal(err)
}
}

Expand Down Expand Up @@ -144,22 +143,9 @@ func main() {
),
}

for i, vnp := range vnps {
if err := writeCorpusFile(fmt.Sprintf("vnp-%d", i), vnp); err != nil {
panic(err)
for _, vnp := range vnps {
if err := helper.WriteCorpusFileWithPrefix("corpus", vnp, header.PrefixLen); err != nil {
log.Fatal(err)
}
}

}

func writeCorpusFile(name string, data []byte) error {
file, err := os.Create("corpus/" + name)
if err != nil {
return err
}
data = append(getRandomData(1), data...)
if _, err := file.Write(data); err != nil {
return err
}
return file.Close()
}
Binary file removed fuzzing/header/corpus/header-0
Binary file not shown.
Binary file removed fuzzing/header/corpus/header-1
Binary file not shown.
Binary file removed fuzzing/header/corpus/header-2
Binary file not shown.
Binary file removed fuzzing/header/corpus/header-3
Binary file not shown.
Binary file removed fuzzing/header/corpus/header-4
Binary file not shown.
Binary file removed fuzzing/header/corpus/header-5
Binary file not shown.
2 changes: 0 additions & 2 deletions fuzzing/header/corpus/header-6

This file was deleted.

Binary file removed fuzzing/header/corpus/header-7
Binary file not shown.
Binary file removed fuzzing/header/corpus/header-8
Binary file not shown.
1 change: 0 additions & 1 deletion fuzzing/header/corpus/header-9

This file was deleted.

Binary file removed fuzzing/header/corpus/vnp-0
Binary file not shown.
Binary file removed fuzzing/header/corpus/vnp-1
Binary file not shown.
Binary file removed fuzzing/header/corpus/vnp-2
Binary file not shown.
Binary file removed fuzzing/header/corpus/vnp-3
Binary file not shown.
Binary file removed fuzzing/header/corpus/vnp-4
Binary file not shown.
8 changes: 6 additions & 2 deletions fuzzing/header/fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ import (

const version = protocol.VersionTLS

// PrefixLen is the number of bytes used for configuration
const PrefixLen = 1

// Fuzz fuzzes the QUIC header.
//go:generate go run ./cmd/corpus.go
func Fuzz(data []byte) int {
if len(data) < 1 {
if len(data) < PrefixLen {
return 0
}
connIDLen := int(data[0] % 21)
data = data[1:]
data = data[PrefixLen:]

if wire.IsVersionNegotiationPacket(data) {
return fuzzVNP(data)
Expand Down
Loading