zorldo

Goofing around with Ebiten
git clone git://bsandro.tech/zorldo
Log | Files | Refs | README

stdlibfuzz.go (1018B)


      1 // Code generated by gen.go. DO NOT EDIT.
      2 
      3 // Copyright 2019 The Go Authors. All rights reserved.
      4 // Use of this source code is governed by a BSD-style
      5 // license that can be found in the LICENSE file.
      6 
      7 //go:build gofuzz
      8 // +build gofuzz
      9 
     10 package png
     11 
     12 import (
     13 	"bytes"
     14 	"fmt"
     15 )
     16 
     17 func Fuzz(data []byte) int {
     18 	cfg, err := DecodeConfig(bytes.NewReader(data))
     19 	if err != nil {
     20 		return 0
     21 	}
     22 	if cfg.Width*cfg.Height > 1e6 {
     23 		return 0
     24 	}
     25 	img, err := Decode(bytes.NewReader(data))
     26 	if err != nil {
     27 		return 0
     28 	}
     29 	levels := []CompressionLevel{
     30 		DefaultCompression,
     31 		NoCompression,
     32 		BestSpeed,
     33 		BestCompression,
     34 	}
     35 	for _, l := range levels {
     36 		var w bytes.Buffer
     37 		e := &Encoder{CompressionLevel: l}
     38 		err = e.Encode(&w, img)
     39 		if err != nil {
     40 			panic(err)
     41 		}
     42 		img1, err := Decode(&w)
     43 		if err != nil {
     44 			panic(err)
     45 		}
     46 		got := img1.Bounds()
     47 		want := img.Bounds()
     48 		if !got.Eq(want) {
     49 			fmt.Printf("bounds0: %#v\n", want)
     50 			fmt.Printf("bounds1: %#v\n", got)
     51 			panic("bounds have changed")
     52 		}
     53 	}
     54 	return 1
     55 }