-
Notifications
You must be signed in to change notification settings - Fork 48
/
flate.go
49 lines (46 loc) · 935 Bytes
/
flate.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
43
44
45
46
47
48
49
// Copyright 2015 go-fuzz project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package flate
import (
"bytes"
"compress/flate"
"io/ioutil"
)
func Fuzz(data []byte) int {
r := bytes.NewReader(data)
fr := flate.NewReader(r)
data1, err := ioutil.ReadAll(fr)
if _, ok := err.(flate.InternalError); ok {
panic(err)
}
if err != nil {
return 0
}
for level := 0; level <= 9; level++ {
buf := new(bytes.Buffer)
fw, err := flate.NewWriter(buf, level)
if err != nil {
panic(err)
}
n, err := fw.Write(data1)
if n != len(data1) {
panic("short write")
}
if err != nil {
panic(err)
}
err = fw.Close()
if err != nil {
panic(err)
}
fr1 := flate.NewReader(buf)
data2, err := ioutil.ReadAll(fr1)
if err != nil {
panic(err)
}
if bytes.Compare(data1, data2) != 0 {
panic("not equal")
}
}
return 1
}