forked from dvyukov/go-fuzz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (38 loc) · 1010 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2015 Dmitry Vyukov. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package mime
import (
"fmt"
"mime"
"github.com/dvyukov/go-fuzz/examples/fuzz"
)
func Fuzz(data []byte) int {
sdata := string(data)
mt, params, err := mime.ParseMediaType(sdata)
if err != nil {
return 0
}
sdata1 := mime.FormatMediaType(mt, params)
mt1, params1, err := mime.ParseMediaType(sdata1)
if err != nil {
if err.Error() == "mime: no media type" {
// https://github.com/golang/go/issues/11289
return 0
}
if err.Error() == "mime: invalid media parameter" {
// https://github.com/golang/go/issues/11290
return 0
}
fmt.Printf("%q(%q, %+v) -> %q\n", sdata, mt, params, sdata1)
panic(err)
}
if !fuzz.DeepEqual(mt, mt1) {
fmt.Printf("%q -> %q\n", mt, mt1)
panic("mediatype changed")
}
if !fuzz.DeepEqual(params, params1) {
fmt.Printf("%+v -> %+v\n", params, params1)
panic("params changed")
}
return 1
}