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
RafayGhafoorf committed Nov 29, 2023
1 parent 5b9cc3f commit f128e5e
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 f128e5e

Please sign in to comment.