fuzzcheck

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
const MinLeak = 8

MinLeak is the shortest input substring that counts as repeated input (AD-3).

Variables

View Source
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

func CheckRegistry(t testing.TB, kind string, registered []string)

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

func EntryProblems(inv []Entry, kind string, has HasTarget) []string

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

func Leak(input []byte, text string, fixed ...string) string

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

func NoInput(t testing.TB, input []byte, field, text string, fixed ...string)

NoInput fails t when text (named by field) repeats a MinLeak-byte substring of input outside the fixed vocabulary.

func Problems

func Problems(inv []Entry, kind string, registered []string, has HasTarget) []string

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

func RepoRoot(t testing.TB) string

RepoRoot returns the module root (the directory holding go.mod) above the test's working directory.

func SchemaVocab

func SchemaVocab(data []byte) []string

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.

func Targets

func Targets(dir string) ([]string, error)

Targets returns the fuzz targets declared in the _test.go files of dir.

func Warnings

func Warnings(t testing.TB, input []byte, ws []model.Warning, fixed ...string)

Warnings fails t when a warning has an undocumented code or a malformed detail code, or when its Location or DetailCode repeats input outside fixed. The warning's own documented code is fixed vocabulary.

func Within

func Within(t testing.TB, what string, got, limit int)

Within fails t when got passes limit (an AD-26 size, depth or entry limit).

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.

func Pending

func Pending(inv []Entry) []Entry

Pending returns the pending entries.

type HasTarget

type HasTarget func(dir, target string) bool

HasTarget reports whether target is declared as func target(...) in a _test.go file of the package directory dir (relative to root).

func SourceTargets

func SourceTargets(root string) HasTarget

SourceTargets returns a HasTarget that reads the _test.go files under root.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL