github.com/decred/dcrlnd@v0.7.6/fuzz/lnwire/query_short_chan_ids_zlib.go (about) 1 //go:build gofuzz 2 // +build gofuzz 3 4 package lnwirefuzz 5 6 import ( 7 "bytes" 8 "compress/zlib" 9 "encoding/binary" 10 11 "github.com/decred/dcrlnd/lnwire" 12 ) 13 14 // Fuzz_query_short_chan_ids_zlib is used by go-fuzz. 15 func Fuzz_query_short_chan_ids_zlib(data []byte) int { 16 17 var buf bytes.Buffer 18 zlibWriter := zlib.NewWriter(&buf) 19 _, err := zlibWriter.Write(data) 20 if err != nil { 21 // Zlib bug? 22 panic(err) 23 } 24 25 if err := zlibWriter.Close(); err != nil { 26 // Zlib bug? 27 panic(err) 28 } 29 30 compressedPayload := buf.Bytes() 31 32 chainhash := []byte("00000000000000000000000000000000") 33 numBytesInBody := len(compressedPayload) + 1 34 zlibByte := []byte("\x01") 35 36 bodyBytes := make([]byte, 2) 37 binary.BigEndian.PutUint16(bodyBytes, uint16(numBytesInBody)) 38 39 payload := append(chainhash, bodyBytes...) 40 payload = append(payload, zlibByte...) 41 payload = append(payload, compressedPayload...) 42 43 // Prefix with MsgQueryShortChanIDs. 44 payload = prefixWithMsgType(payload, lnwire.MsgQueryShortChanIDs) 45 46 // Pass the message into our general fuzz harness for wire messages! 47 return harness(payload) 48 }