//go:build gofuzz package tce // Fuzz is the OSS-Fuzz entry point for the primitive TCE codec. It asserts two // totality properties of PROTOCOL.md section 12.4 against arbitrary input: // // - the decoder never panics, hangs or returns a usable object alongside an // error (totality); the decoder is walked field by field and each read // ignores its result; // - CanonicalNumber (section 5.1) is total over arbitrary text and only ever // produces an already-canonical token, so a malformed number is rejected // rather than silently accepted. // // The function is compiled only under the "gofuzz" build tag (go-fuzz / // OSS-Fuzz). Under that tag the Go test files are excluded, so there is no // clash with the testing.F-based fuzz targets in the package. func Fuzz(data []byte) int { d := NewDecoder(data) _, _ = d.Header() _, _ = d.Uvarint() _, _ = d.String(1 << 20) _, _ = d.Map(0) _, _ = d.Timestamp(true) _, _ = d.Identity() // Signal interesting inputs that survive canonicalization, guiding the // fuzzer toward the number parser's branches. if c, err := CanonicalNumber(string(data)); err == nil && IsCanonicalNumber(c) { return 1 } return 0 }