{"id":18894150,"url":"https://github.com/trailofbits/go-fuzz-utils","last_synced_at":"2025-06-21T16:39:13.459Z","repository":{"id":45366753,"uuid":"399529171","full_name":"trailofbits/go-fuzz-utils","owner":"trailofbits","description":null,"archived":false,"fork":false,"pushed_at":"2024-08-30T17:54:02.000Z","size":106,"stargazers_count":19,"open_issues_count":2,"forks_count":3,"subscribers_count":19,"default_branch":"main","last_synced_at":"2025-03-28T12:51:14.674Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trailofbits.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-24T16:10:36.000Z","updated_at":"2024-08-30T17:53:58.000Z","dependencies_parsed_at":"2024-06-18T22:43:46.651Z","dependency_job_id":"4068912a-a308-4381-9575-7f9dcb2f3991","html_url":"https://github.com/trailofbits/go-fuzz-utils","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailofbits%2Fgo-fuzz-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailofbits%2Fgo-fuzz-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailofbits%2Fgo-fuzz-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trailofbits%2Fgo-fuzz-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trailofbits","download_url":"https://codeload.github.com/trailofbits/go-fuzz-utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248984396,"owners_count":21193742,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T08:18:36.481Z","updated_at":"2025-04-15T00:31:55.762Z","avatar_url":"https://github.com/trailofbits.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-fuzz-utils\n`go-fuzz-utils` is a helper package for use with [go-fuzz](https://github.com/dvyukov/go-fuzz) or other fuzzing utilities. It provides a simple interface to produce random values for various data types and can recursively populate complex structures from raw fuzz data generated by `go-fuzz`. Spend more time writing property tests, and less time with ugly data type conversions, edge cases supporting full value ranges, `nil` cases, etc. Simply feed `go-fuzz` data into `go-fuzz-utils` to produce fuzzed objects and use them in your property tests as needed.\n\nWhen populating variables, you can configure a number of parameters:\n- Minimum/maximum sizes of strings, maps, slices\n- Probability of `nil` for maps, slices, pointers\n- Depth limit for nested structures\n- Toggle for filling unexported fields in structures\n- Probability of skipping a field when filling (to randomly fuzz over valid structure fields)\n\n## Setup\nImport this package into your `go-fuzz` tests:\n```go\nimport \"github.com/trailofbits/go-fuzz-utils\"\n```\n\nConstruct a new `TypeProvider` using `NewTypeProvider(...)`.\n```go\nfunc Fuzz(data []byte) int {\n\t// Create a new type provider\n\ttp, err := go_fuzz_utils.NewTypeProvider(data)\n\tif err != nil {\n\t\treturn 0 // not enough data was supplied, exit gracefully for the next fuzzing iteration\n\t}\n[...]\n```\nNote: the data `go-fuzz` generates on some runs may be too small to construct the `TypeProvider` or derive all the values needed for your test. Ensure errors are handled appropriately. If one is encountered, exit gracefully to continue to the next run where more data may be produced. Fill parameters such as mapping/slice/string length and `nil` probability can be set using the `SetParams[...]` methods.\n\n## Simple data types\nYou can obtain the necessary type of data with exported functions such as:\n```go\n\t// Obtain a byte\n\tb, err := tp.GetByte()\n...\n\t// Obtain a bool\n\tbl, err := tp.GetBool()\n...\n\t// Obtain an int16\n\ti16, err := tp.GetInt16()\n...\n\t// Obtain a float32\n\tf32, err := tp.GetFloat32()\n...\n\t// Obtain a fixed-length string\n\tstrFixed, err := tp.GetFixedString(7)\n...\n\t// Obtain a dynamic-length string\n\tstrDynamic, err := tp.GetString() // uses TypeProvider parameters to determine length/nil possibility\n...\n\t// Obtain a fixed-length byte array\n\tbytesFixed, err := tp.GetNBytes(2)\n...\n\t// Obtain a dynamic-length byte array\n\tbytesDynamic, err := tp.GetBytes() // uses TypeProvider parameters to determine length/nil possibility\n```\n\n\n## Structures\n`go-fuzz-utils` exposes a generic `Fill(...)` method which can populate simple data types, mappings, arrays, and arbitrary structures recursively via reflection. \n\nFor example, given the following structure:\n```go\n\ttype Person struct {\n\t\tID uint64\n\t\tName string\n\t\tPhoto []byte\n\t\tEmployed bool\n\t\tEmergencyContact *Person\n\t}\n```\n\nYou can simply perform a `Fill` call to populate it with the fuzz data. Even though `Person` has a circular reference in `EmergencyContact`, you can configure depth limits and `nil` bias settings to prevent infinite loops while giving us various deeply nested structures.\n```go\n\t// Create a person struct and fill it recursively. \n\tvar p Person\n\terr := tp.Fill(\u0026p)    \n```\n\nSimilarly, you can fill other data types as needed:\n```go\n\t// Create an array of mappings and fill them\n\tmappingArr := make([]map[string]int, 15)\n\terr = tp.Fill(\u0026mappingArr)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrailofbits%2Fgo-fuzz-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrailofbits%2Fgo-fuzz-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrailofbits%2Fgo-fuzz-utils/lists"}