Documentation
¶
Overview ¶
Package fuzzcheck holds the assertions every fuzz target shares and the fuzz inventory (Story 4.13). It is imported by tests only.
The assertions are: no panic (the fuzz engine fails a target that panics; a target whose code under test recovers its own panics checks for the recovery's trace), AD-26 limits honoured (Within) and AD-3 text hygiene (NoInput, Warnings): no warning field, issue or message repeats any substring of the input of MinLeak bytes or more.
Index ¶
- Constants
- Variables
- func CheckRegistry(t testing.TB, kind string, registered []string)
- func EntryProblems(inv []Entry, kind string, has HasTarget) []string
- func Leak(input []byte, text string, fixed ...string) string
- func NoInput(t testing.TB, input []byte, field, text string, fixed ...string)
- func Problems(inv []Entry, kind string, registered []string, has HasTarget) []string
- func RepoRoot(t testing.TB) string
- func SchemaVocab(data []byte) []string
- func Targets(dir string) ([]string, error)
- func Warnings(t testing.TB, input []byte, ws []model.Warning, fixed ...string)
- func Within(t testing.TB, what string, got, limit int)
- type Entry
- type HasTarget
Constants ¶
const ( // KindDecoder is a decode adapter or an encoding the standard adapter decodes. KindDecoder = "decoder" // KindParseFormat is a surface parse format (registry.ParseFormats). KindParseFormat = "parse-format" // KindParser is any other parser or loader of untrusted input. KindParser = "parser" )
Inventory kinds. KindDecoder and KindParseFormat entries are tied to a registry: CheckRegistry fails when a registered name has no entry, so a new decoder or parse format cannot ship without a fuzz target.
const MinLeak = 8
MinLeak is the shortest input substring that counts as repeated input (AD-3).
Variables ¶
var Inventory = []Entry{ {Kind: KindDecoder, Name: "passthrough", Dir: "internal/decode", Target: "FuzzDecode"}, {Kind: KindDecoder, Name: "standard", Dir: "internal/decode", Target: "FuzzDecode"}, {Kind: KindDecoder, Name: "base64", Dir: "internal/decode", Target: "FuzzBase64"}, {Kind: KindDecoder, Name: "percent", Dir: "internal/decode", Target: "FuzzPercent"}, {Kind: KindDecoder, Name: "json-escape", Dir: "internal/decode", Target: "FuzzJSONEscape"}, {Kind: KindDecoder, Name: "env", Dir: "internal/decode", Target: "FuzzEnv"}, {Kind: KindParseFormat, Name: "json", Dir: "internal/source/surface/parse", Target: "FuzzParseJSON"}, {Kind: KindParseFormat, Name: "jsonc", Dir: "internal/source/surface/parse", Target: "FuzzParseJSONC"}, {Kind: KindParseFormat, Name: "toml", Dir: "internal/source/surface/parse", Target: "FuzzParseTOML"}, {Kind: KindParseFormat, Name: "yaml", Dir: "internal/source/surface/parse", Target: "FuzzParseYAML"}, {Kind: KindParseFormat, Name: "ini", Dir: "internal/source/surface/parse", Target: "FuzzParseINI"}, {Kind: KindParseFormat, Name: "dotenv", Dir: "internal/source/surface/parse", Target: "FuzzParseDotenv"}, {Kind: KindParseFormat, Name: "shell-history", Dir: "internal/source/surface/parse", Target: "FuzzParseShellHistory"}, {Kind: KindParseFormat, Name: "jsonl", Dir: "internal/source/surface/parse", Target: "FuzzParseJSONL"}, {Kind: KindParseFormat, Name: "ipynb", Dir: "internal/source/surface/parse", Target: "FuzzParseIPYNB"}, {Kind: KindParser, Name: "notebook reader", Dir: "internal/source/surface/parse", Target: "FuzzReadNotebook"}, {Kind: KindParser, Name: "git log -p diff", Dir: "internal/gitx", Target: "FuzzParseDiff"}, {Kind: KindParser, Name: ".tokenhound-ignore grammar", Dir: "internal/config", Target: "FuzzIgnore"}, {Kind: KindParser, Name: "ignore glob", Dir: "internal/ignore", Target: "FuzzGlob"}, {Kind: KindParser, Name: "inline tokenhound:allow", Dir: "internal/detect", Target: "FuzzInlineAllow"}, {Kind: KindParser, Name: "baseline loader", Dir: "internal/config", Target: "FuzzParseBaseline"}, {Kind: KindParser, Name: "config loader", Dir: "internal/config", Target: "FuzzParse"}, {Kind: KindParser, Name: "registry loader", Dir: "internal/registry", Target: "FuzzLoad"}, {Kind: KindParser, Name: "Claude Code hook stdin (PreToolUse)", Dir: "internal/hook", Target: "FuzzClaudeCodeHook"}, {Kind: KindParser, Name: "Claude Code hook stdin (SessionEnd)", Dir: "internal/hook", Target: "FuzzSessionEnd"}, {Kind: KindParser, Name: "Claude Code settings file", Dir: "internal/agenthook", Target: "FuzzSettings"}, {Kind: KindParser, Name: "MCP request decoding", Dir: "internal/mcpserver", Target: "FuzzServe"}, {Kind: KindParser, Name: "archive expansion (zip, tar, gz, nested, archive-in-base64)", Pending: "Story 5.5"}, {Kind: KindParser, Name: "image layer reader", Pending: "Story 5.6"}, {Kind: KindParser, Name: "gitleaks importer", Pending: "Story 5.9"}, {Kind: KindParser, Name: "TruffleHog importer", Pending: "Story 5.9"}, {Kind: KindParser, Name: "custom detector loader", Pending: "Story 5.2"}, {Kind: KindParser, Name: "Codex hook adapter stdin", Pending: "Story 5.1"}, {Kind: KindParser, Name: "Cursor hook adapter stdin", Pending: "Story 5.1"}, }
Inventory lists every parser and decoder of v1.0 with its fuzz target, and the Epic 5 parsers with the story that must add theirs.
Functions ¶
func CheckRegistry ¶
CheckRegistry fails t for every problem Problems finds in Inventory for the registered names of kind, looking targets up in the repository's test files.
func EntryProblems ¶
EntryProblems checks the entries of kind (every kind when kind is empty): a non-pending entry names a directory and a FuzzXxx target that exists; a pending entry names an Epic 5 story and no target.
func Leak ¶
Leak returns the first substring of text, MinLeak bytes long, that also occurs in input, or "" when there is none. Every fixed string (fixed vocabulary such as a file name the test chose or a documented code) of MinLeak bytes or more is cut out of text first, so a window never spans or includes one. Shorter fixed strings are ignored: cutting text at a short word such as "on" or "id" would split a repeated value into pieces too short to count and hide the leak.
func NoInput ¶
NoInput fails t when text (named by field) repeats a MinLeak-byte substring of input outside the fixed vocabulary.
func Problems ¶
Problems returns what is wrong with the inventory for one registry: each name in registered with no entry of kind, each entry of kind not registered, and each entry of kind whose target is missing. inv is normally Inventory.
func RepoRoot ¶
RepoRoot returns the module root (the directory holding go.mod) above the test's working directory.
func SchemaVocab ¶
SchemaVocab returns the names a message or location built from a JSON Schema may repeat without repeating input: every property name and every string enum or const value, at any depth. Descriptions, patterns, ids and other schema text are not vocabulary. Invalid JSON gives nil.
Types ¶
type Entry ¶
type Entry struct {
Kind string
// Name is the registered name (decoders, parse formats) or a short label.
Name string
// Dir is the package directory holding Target, relative to the repository root.
Dir string
// Target is the FuzzXxx function; empty when Pending.
Target string
// Pending names the Epic 5 story that ships the parser and must add its target.
Pending string
}
Entry is one parser or decoder and its fuzz target.
type HasTarget ¶
HasTarget reports whether target is declared as func target(...) in a _test.go file of the package directory dir (relative to root).
func SourceTargets ¶
SourceTargets returns a HasTarget that reads the _test.go files under root.