zig/lib/std
Kendall Condon 93775de45f rework fuzz testing to be smith based
-- On the standard library side:

The `input: []const u8` parameter of functions passed to `testing.fuzz`
has changed to `smith: *testing.Smith`. `Smith` is used to generate
values from libfuzzer or input bytes generated by libfuzzer.

`Smith` contains the following base methods:
* `value` as a generic method for generating any type
* `eos` for generating end-of-stream markers. Provides the additional
  guarantee `true` will eventually by provided.
* `bytes` for filling a byte array.
* `slice` for filling part of a buffer and providing the length.

`Smith.Weight` is used for giving value ranges a higher probability of
being selected. By default, every value has a weight of zero (i.e. they
will not be selected). Weights can only apply to values that fit within
a u64. The above functions have corresponding ones that accept weights.
Additionally, the following functions are provided:
* `baselineWeights` which provides a set of weights containing every
  possible value of a type.
* `eosSimpleWeighted` for unique weights for `true` and `false`
* `valueRangeAtMost` and `valueRangeLessThan` for weighing only a range
  of values.

-- On the libfuzzer and abi side:

--- Uids

These are u32s which are used to classify requested values. This solves
the problem of a mutation causing a new value to be requested and
shifting all future values; for example:

1. An initial input contains the values 1, 2, 3 which are interpreted
as a, b, and c respectively by the test.

2. The 1 is mutated to a 4 which causes the test to request an extra
value interpreted as d. The input is now 4, 2, 3, 5 (new value) which
the test corresponds to a, d, b, c; however, b and c no longer
correspond to their original values.

Uids contain a hash component and type component. The hash component
is currently determined in `Smith` by taking a hash of the calling
`@returnAddress()` or via an argument in the corresponding `WithHash`
functions. The type component is used extensively in libfuzzer with its
hashmaps.

--- Mutations

At the start of a cycle (a run), a random number of values to mutate is
selected with less being exponentially more likely. The indexes of the
values are selected from a selected uid with a logarithmic bias to uids
with more values.

Mutations may change a single values, several consecutive values in a
uid, or several consecutive values in the uid-independent order they
were requested. They may generate random values, mutate from previous
ones, or copy from other values in the same uid from the same input or
spliced from another.

For integers, mutations from previous ones currently only generates
random values. For bytes, mutations from previous mix new random data
and previous bytes with a set number of mutations.

--- Passive Minimization

A different approach has been taken for minimizing inputs: instead of
trying a fixed set of mutations when a fresh input is found, the input
is instead simply added to the corpus and removed when it is no longer
valuable.

The quality of an input is measured based off how many unique pcs it
hit and how many values it needed from the fuzzer. It is tracked which
inputs hold the best qualities for each pc for hitting the minimum and
maximum unique pcs while needing the least values.

Once all an input's qualities have been superseded for the pcs it hit,
it is removed from the corpus.

-- Comparison to byte-based smith

A byte-based smith would be much more inefficient and complex than this
solution. It would be unable to solve the shifting problem that Uids
do. It is unable to provide values from the fuzzer past end-of-stream.
Even with feedback, it would be unable to act on dynamic weights which
have proven essential with the updated tests (e.g. to constrain values
to a range).

-- Test updates

All the standard library tests have been updated to use the new smith
interface. For `Deque`, an ad hoc allocator was written to improve
performance and remove reliance on heap allocation. `TokenSmith` has
been added to aid in testing Ast and help inform decisions on the smith
interface.
2025-11-23 14:58:22 -05:00
..
Build rework fuzz testing to be smith based 2025-11-23 14:58:22 -05:00
builtin std.builtin.assembly: add Clobbers for kvx 2025-11-10 09:40:42 +01:00
c remove all Oracle Solaris support 2025-10-27 07:35:38 -07:00
compress rework fuzz testing to be smith based 2025-11-23 14:58:22 -05:00
crypto Merge pull request #23733 from alichraghi/bp 2025-11-23 07:50:29 +00:00
debug update deprecated ArrayListUnmanaged usage (#25958) 2025-11-20 14:46:23 -08:00
dwarf
fmt all: replace all @Type usages 2025-11-22 22:42:38 +00:00
fs system specific errno 2025-11-20 15:03:23 -08:00
hash all: replace all @Type usages 2025-11-22 22:42:38 +00:00
heap DebugAllocator: only determine tty config if needed 2025-11-23 12:20:58 -05:00
http Revert "std.http: disable failing test on 32-bit arm" 2025-11-01 11:21:28 -04:00
Io all: replace all @Type usages 2025-11-22 22:42:38 +00:00
json rework fuzz testing to be smith based 2025-11-23 14:58:22 -05:00
math all: replace all @Type usages 2025-11-22 22:42:38 +00:00
mem std.mem.Allocator: fix resize doc comment 2025-10-22 11:41:16 +02:00
meta all: replace all @Type usages 2025-11-22 22:42:38 +00:00
os Revert "std.os.linux.sparc64: use icc instead of xcc in asm clobbers" 2025-11-23 07:27:45 +01:00
posix represent Mac Catalyst as aarch64-maccatalyst-none rather than aarch64-ios-macabi 2025-11-14 11:33:35 +01:00
process represent Mac Catalyst as aarch64-maccatalyst-none rather than aarch64-ios-macabi 2025-11-14 11:33:35 +01:00
Random
sort
tar compiler: update for introduction of std.Io 2025-10-29 06:20:49 -07:00
Target std.Target.x86: refresh from update_cpu_features.zig 2025-11-13 22:29:28 +01:00
testing rework fuzz testing to be smith based 2025-11-23 14:58:22 -05:00
Thread std.Io.Threaded: slightly different semantics 2025-11-21 19:54:41 -08:00
time
tz
unicode
valgrind
zig rework fuzz testing to be smith based 2025-11-23 14:58:22 -05:00
zon update deprecated ArrayListUnmanaged usage (#25958) 2025-11-20 14:46:23 -08:00
array_hash_map.zig update deprecated ArrayListUnmanaged usage (#25958) 2025-11-20 14:46:23 -08:00
array_list.zig std.ArrayList: actaully memset to undefined in shrinkRetainingCapacity and clearRetainingCapacity 2025-11-06 05:30:41 -08:00
ascii.zig std: Skip element comparisons if mem.order args point to same memory 2025-10-31 18:34:33 -07:00
atomic.zig std.atomic: define cache line size for alpha, hppa, microblaze, sh 2025-10-23 09:27:17 +02:00
base64.zig Base64DecoderWithIgnore.calcSizeUpperBound cannot return an error (#25834) 2025-11-07 08:16:34 +01:00
bit_set.zig
BitStack.zig
buf_map.zig
buf_set.zig
Build.zig allow specifying mode in --debug-rt 2025-11-23 13:58:27 -05:00
builtin.zig compiler: replace @Type with individual type-creating builtins 2025-11-22 22:42:37 +00:00
c.zig system specific errno 2025-11-20 15:03:23 -08:00
coff.zig Coff: implement threadlocal variables 2025-10-10 22:47:47 -07:00
compress.zig
crypto.zig Add ML-DSA post-quantum signatures (#25862) 2025-11-10 14:11:30 +01:00
debug.zig rework fuzz testing to be smith based 2025-11-23 14:58:22 -05:00
deque.zig rework fuzz testing to be smith based 2025-11-23 14:58:22 -05:00
DoublyLinkedList.zig *LinkedList.remove() assumes node is in the list 2025-10-25 21:10:02 -07:00
dwarf.zig
dynamic_library.zig represent Mac Catalyst as aarch64-maccatalyst-none rather than aarch64-ios-macabi 2025-11-14 11:33:35 +01:00
elf.zig posix: reduce the number of assumptions made by dl_iterate_phdr 2025-11-09 03:31:26 -05:00
enums.zig all: replace all @Type usages 2025-11-22 22:42:38 +00:00
fmt.zig all: replace all @Type usages 2025-11-22 22:42:38 +00:00
fs.zig represent Mac Catalyst as aarch64-maccatalyst-none rather than aarch64-ios-macabi 2025-11-14 11:33:35 +01:00
gpu.zig
hash.zig all: replace all @Type usages 2025-11-22 22:42:38 +00:00
hash_map.zig update deprecated ArrayListUnmanaged usage (#25958) 2025-11-20 14:46:23 -08:00
heap.zig MemoryPool: add unmanaged variants and make them the default 2025-11-15 09:30:57 +00:00
http.zig std.http: stop assuming previous chunk state 2025-11-20 10:42:21 +00:00
Io.zig all: replace all @Type usages 2025-11-22 22:42:38 +00:00
json.zig
leb128.zig
log.zig all: replace all @Type usages 2025-11-22 22:42:38 +00:00
macho.zig std.debug: split up Mach-O debug info handling 2025-11-20 10:42:20 +00:00
math.zig all: replace all @Type usages 2025-11-22 22:42:38 +00:00
mem.zig all: replace all @Type usages 2025-11-22 22:42:38 +00:00
meta.zig all: replace all @Type usages 2025-11-22 22:42:38 +00:00
multi_array_list.zig all: replace all @Type usages 2025-11-22 22:42:38 +00:00
once.zig
os.zig represent Mac Catalyst as aarch64-maccatalyst-none rather than aarch64-ios-macabi 2025-11-14 11:33:35 +01:00
pdb.zig
pie.zig std.pie: add missing clobbers on alpha and sparc 2025-11-14 12:19:38 +01:00
posix.zig system specific errno 2025-11-20 15:03:23 -08:00
priority_dequeue.zig
priority_queue.zig
process.zig system specific errno 2025-11-20 15:03:23 -08:00
Progress.zig Merge pull request #25898 from jacobly0/elfv2-progress 2025-11-20 04:33:04 -08:00
Random.zig std.Io.net: progress towards DNS resolution 2025-10-29 06:20:48 -07:00
SemanticVersion.zig
simd.zig std.simd: suggest 1024-bit vectors for kvx 2025-11-10 09:40:44 +01:00
SinglyLinkedList.zig SinglyLinkedList.remove docs: Assumes -> asserts 2025-10-25 21:28:54 -07:00
sort.zig
start.zig std.start: add kvx support 2025-11-10 09:40:44 +01:00
static_string_map.zig
std.zig all: replace all @Type usages 2025-11-22 22:42:38 +00:00
tar.zig update deprecated ArrayListUnmanaged usage (#25958) 2025-11-20 14:46:23 -08:00
Target.zig std.Target: remove Abi.code16 2025-11-23 10:22:03 +01:00
testing.zig rework fuzz testing to be smith based 2025-11-23 14:58:22 -05:00
Thread.zig std.Thread: update doc comments 2025-11-21 19:54:41 -08:00
time.zig represent Mac Catalyst as aarch64-maccatalyst-none rather than aarch64-ios-macabi 2025-11-14 11:33:35 +01:00
treap.zig
tz.zig
unicode.zig std: move some windows path checking logic 2025-10-29 06:20:50 -07:00
Uri.zig compiler: update for introduction of std.Io 2025-10-29 06:20:49 -07:00
valgrind.zig
wasm.zig
zig.zig rework fuzz testing to be smith based 2025-11-23 14:58:22 -05:00
zip.zig
zon.zig