Skip to content

Commit

Permalink
Merge pull request #18 from dgryski/fuzz-crashers
Browse files Browse the repository at this point in the history
Fix crashers found by go-fuzz
  • Loading branch information
ARolek committed Aug 17, 2015
2 parents b1bf7d7 + ebaaab0 commit 527f889
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions color.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func (color *Color) readNameLen(r io.Reader) error {

// Decode the color's name.
func (color *Color) readName(r io.Reader) (err error) {
if color.nameLen == 0 {
return
}

// make array for our color name based on block length
name := make([]uint16, color.nameLen) // assumes the nameLen was already defined.
if err = binary.Read(r, binary.BigEndian, &name); err != nil {
Expand Down
14 changes: 14 additions & 0 deletions fuzz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// +build gofuzz

package ase

import "bytes"

func Fuzz(data []byte) int {

if _, err := Decode(bytes.NewReader(data)); err != nil {
return 0
}

return 1
}
18 changes: 18 additions & 0 deletions fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ase

import (
"strings"
"testing"
)

func TestFuzzCrashers(t *testing.T) {

var crashers = []string{
"ASEF\x00\x01000000\xc0\x010000\x00\x00",
"ASEF00\x00\x000000\x00\x010000\x00\x00",
}

for _, f := range crashers {
Decode(strings.NewReader(f))
}
}
4 changes: 4 additions & 0 deletions group.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func (group *Group) readNameLen(r io.Reader) error {

// Decode a group's name.
func (group *Group) readName(r io.Reader) (err error) {
if group.nameLen == 0 {
return
}

// make array for our color name based on block length
name := make([]uint16, group.nameLen)
if err = binary.Read(r, binary.BigEndian, &name); err != nil {
Expand Down

0 comments on commit 527f889

Please sign in to comment.