Skip to content

Commit

Permalink
tiff: add Fuzz function
Browse files Browse the repository at this point in the history
This change adds a sample Fuzz test function to package tiff, under
the gofuzz build tag. The function is based on the tiff/tiff.go code,
from github.com/dvyukov/go-fuzz-corpus.

Fixes golang/go#30719
Updates golang/go#19109

Change-Id: I78771e9a1bd01651ba6ca421ba41f0c0e95d0c53
Reviewed-on: https://go-review.googlesource.com/c/image/+/167097
Run-TryBot: Dmitry Vyukov <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: thepudds <[email protected]>
Reviewed-by: Josh Bleecher Snyder <[email protected]>
Reviewed-by: Dmitry Vyukov <[email protected]>
  • Loading branch information
acln0 authored and dvyukov committed Mar 21, 2019
1 parent 0694c2d commit 3fc05d4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tiff/fuzz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build gofuzz

package tiff

import "bytes"

func Fuzz(data []byte) int {
cfg, err := DecodeConfig(bytes.NewReader(data))
if err != nil {
return 0
}
if cfg.Width*cfg.Height > 1e6 {
return 0
}
img, err := Decode(bytes.NewReader(data))
if err != nil {
return 0
}
var w bytes.Buffer
err = Encode(&w, img, nil)
if err != nil {
panic(err)
}
return 1
}

0 comments on commit 3fc05d4

Please sign in to comment.