Something went wrong. Try again.
A URI parser and formatter for Zig, modelled on Python's hyperlink package, with LDAP URLs, file: URIs and sdns:// DNS stamps beside it.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
//! Fuzz tests.//!//! Every test here states a property that has to hold for *any* input, and//! lets `std.testing.Smith` generate the inputs. Smith is structure-aware: it//! is asked for a length, an index or a byte from a restricted alphabet rather//! than for a flat blob, so the fuzzer mutates the shape of a URI reference//! instead of hammering a string that stops parsing after the first byte.//!//! `zig build test` compiles these but runs each one only against one smoke//! input, so they cost the normal test run almost nothing. Searching is either//! `zig build test --fuzz=N`, which uses Zig's own fuzzer, or `zig build//! fuzz-run`, which is a loop of our own -- the table at the bottom of this//! file is what that driver runs, and `tools/fuzz.zig` says why it exists.//!//! Each target is therefore a named function rather than a closure inside its//! test: the test runner reaches it one way and the driver the other.//!//! The properties, in the order they appear://!//! * parsing then writing then parsing again yields the same components,//! and writing is a fixed point rather than merely convergent;//! * that holds in IRI form too, where permitted non-ASCII is written//! literally rather than escaped;//! * normalization is idempotent, and leaves a reference that still//! round-trips;//! * so does resolving one reference against another;//! * a filesystem path survives being turned into a `file:` URI and read//! back, on either platform's path syntax;//! * percent-encoding round-trips any byte string exactly;//! * so does Punycode, over any sequence of code points;//! * hand-built components -- the ones parsing can never produce, with a//! `/` inside a path segment or an `@` inside a host -- survive being//! written and read back;//! * and an LDAP URL round-trips too, over the delimiters that parser has//! opinions about rather than the ones RFC 3986 does.
const builtin = @import("builtin");const std = @import("std");
const build_options = @import("build_options");const z46 = @import("z46");
const components = @import("components.zig");const format_mod = @import("format.zig");const percent = @import("percent.zig");const punycode = @import("punycode.zig");
const Allocator = std.mem.Allocator;const Components = components.Components;const Host = components.Host;const QueryParam = components.QueryParam;const DataUrl = @import("data.zig").Url;const LdapUrl = @import("ldap.zig").Url;const stamp = @import("stamp.zig");const Stamp = stamp.Stamp;const Smith = std.testing.Smith;const Uri = @import("uri.zig").Uri;const Weight = Smith.Weight;
/// Where a target gets its memory.////// `std.testing.allocator` does not exist outside a test build, and these/// targets are reached from two: the test runner, which sets this to the/// leak-checking one, and `tools/fuzz.zig`, which is an ordinary program and/// points it at a `DebugAllocator` it checks after every input. A target that/// named the testing allocator directly would compile in one and not the other.pub var backing: Allocator = if (builtin.is_test) std.testing.allocator else undefined;
const expect = std.testing.expect;const expectEqual = std.testing.expectEqual;const expectEqualSlices = std.testing.expectEqualSlices;const expectEqualStrings = std.testing.expectEqualStrings;
/// The bytes a URI parser actually has opinions about: every structural/// delimiter, every sub-delim, `%` and the hex digits that follow it, and a/// few bytes from outside ASCII. Smith only ever emits bytes listed here, so/// the fuzzer spends its budget on structure rather than on payload.////// Weights are relative, and apply to each byte of a range rather than being/// spread across it. Ranges may not overlap.const delimiters: []const Weight = &.{ .value(u8, '%', 8), .value(u8, '/', 8), .value(u8, ':', 6), .value(u8, '?', 4), .value(u8, '#', 4), .value(u8, '@', 4), .value(u8, '[', 3), .value(u8, ']', 3), .value(u8, '.', 3), // sub-delims, and the rest of `unreserved`. .rangeAtMost(u8, '!', '!', 2), // ! .rangeAtMost(u8, '$', '$', 2), // $ .rangeAtMost(u8, '&', '+', 2), // & ' ( ) * + .rangeAtMost(u8, ',', '-', 2), // , - .rangeAtMost(u8, ';', '=', 2), // ; < = .value(u8, '_', 2), .value(u8, '~', 2), // Payload: hex digits (so `%XX` sometimes decodes), one letter past `f` // to stand for the rest of the alphabet, `v` for an IPvFuture literal, // one uppercase letter, a space, and two bytes that are not ASCII at all. .rangeAtMost(u8, '0', '9', 3), .rangeAtMost(u8, 'a', 'f', 3), .value(u8, 'v', 1), .value(u8, 'z', 1), .value(u8, 'Z', 1), .value(u8, ' ', 1), .value(u8, 0xc3, 1), .value(u8, 0xa9, 1), .value(u8, 0xff, 1),};
/// Long enough to hold an authority, a couple of path segments and a query;/// past that a longer input is more of the same.const max_text = 48;
// -- round-tripping text ---------------------------------------------------
/// The central property: components survive a write/read cycle unchanged, and/// the text written from them is a fixed point.////// Output is canonically rather than identically escaped -- `%2f` comes back/// as `%2F` -- so the invariant is about the components and about the second/// write, never about matching the original text.fn checkRoundTrip(text: []const u8, opts: Uri.TextOptions) !void { const alloc = backing;
const a = Uri.parse(alloc, text) catch |err| switch (err) { // Every parse error is a documented rejection of malformed input. error.InvalidScheme, error.InvalidAuthority, error.UnterminatedIPv6Literal, error.InvalidPort, error.InvalidIPv6Literal, error.InvalidPercentEncoding, => return, error.OutOfMemory => return err, }; defer a.deinit();
const once = try a.toText(alloc, opts); defer alloc.free(once);
const b = Uri.parse(alloc, once) catch |err| { std.debug.print("\nre-parsing {s} (from {s}) failed\n", .{ once, text }); return err; }; defer b.deinit();
expect(a.eql(b)) catch |err| { std.debug.print("\ncomponents changed: {s} -> {s}\n", .{ text, once }); return err; }; try expectEqual(a.hash(), b.hash());
const twice = try b.toText(alloc, opts); defer alloc.free(twice); expectEqualStrings(once, twice) catch |err| { std.debug.print("\nunstable output from: {s}\n", .{text}); return err; };}
test "fuzz: parsing delimiter-heavy text round-trips" { try std.testing.fuzz({}, fuzzDelimitedText, .{});}
fn fuzzDelimitedText(_: void, s: *Smith) anyerror!void { var buf: [max_text]u8 = undefined; const n = s.sliceWeightedBytes(&buf, delimiters); try checkRoundTrip(buf[0..n], .{ .with_password = true });}
test "fuzz: parsing arbitrary bytes round-trips" { try std.testing.fuzz({}, fuzzArbitraryText, .{});}
fn fuzzArbitraryText(_: void, s: *Smith) anyerror!void { var buf: [max_text]u8 = undefined; const n = s.slice(&buf); try checkRoundTrip(buf[0..n], .{ .with_password = true });}
test "fuzz: parsing round-trips in IRI form" { try std.testing.fuzz({}, fuzzIriForm, .{});}
// In IRI form the non-ASCII characters RFC 3987 permits are written as// literal UTF-8 instead of being escaped. Components are byte strings// either way, so the same round-trip has to hold.fn fuzzIriForm(_: void, s: *Smith) anyerror!void { var buf: [max_text]u8 = undefined; const n = s.sliceWeightedBytes(&buf, delimiters); try checkRoundTrip(buf[0..n], .{ .form = .iri, .with_password = true });}
test "fuzz: normalization is idempotent" { try std.testing.fuzz({}, fuzzNormalize, .{});}
fn fuzzNormalize(_: void, s: *Smith) anyerror!void { const alloc = backing;
var buf: [max_text]u8 = undefined; const n = s.sliceWeightedBytes(&buf, delimiters); const text = buf[0..n];
const opts: Uri.NormalizeOptions = .{ .scheme = s.value(bool), .host = s.value(bool), .path = s.value(bool), .drop_default_port = s.value(bool), .root_empty_path = s.value(bool), };
const a = Uri.parse(alloc, text) catch return; defer a.deinit();
const first = try a.normalize(alloc, opts); defer first.deinit(); const second = try first.normalize(alloc, opts); defer second.deinit();
expect(first.eql(second)) catch |err| { std.debug.print("\nnormalization is not idempotent: {s}\n", .{text}); return err; };
// A normalized reference is still a reference: writing it and // reading it back has to give the same components. const written = try first.toText(alloc, .{ .with_password = true }); defer alloc.free(written); const reparsed = Uri.parse(alloc, written) catch |err| { std.debug.print("\nre-parsing normalized {s} (from {s}) failed\n", .{ written, text }); return err; }; defer reparsed.deinit(); expect(first.eql(reparsed)) catch |err| { std.debug.print("\nnormalized components changed: {s} -> {s}\n", .{ text, written }); return err; };}
test "fuzz: click resolves to a reference that round-trips" { try std.testing.fuzz({}, fuzzClick, .{});}
fn fuzzClick(_: void, s: *Smith) anyerror!void { const alloc = backing;
var base_buf: [max_text]u8 = undefined; var href_buf: [max_text]u8 = undefined; const base_text = base_buf[0..s.sliceWeightedBytes(&base_buf, delimiters)]; const href_text = href_buf[0..s.sliceWeightedBytes(&href_buf, delimiters)];
const base = Uri.parse(alloc, base_text) catch return; defer base.deinit();
const clicked = base.click(alloc, href_text) catch |err| switch (err) { error.OutOfMemory => return err, // The href failed to parse, which `click` reports as-is. else => return, }; defer clicked.deinit();
const written = try clicked.toText(alloc, .{ .with_password = true }); defer alloc.free(written);
const reparsed = Uri.parse(alloc, written) catch |err| { std.debug.print( "\nre-parsing {s} (from {s} + {s}) failed\n", .{ written, base_text, href_text }, ); return err; }; defer reparsed.deinit();
expect(clicked.eql(reparsed)) catch |err| { std.debug.print( "\nclick components changed: {s} + {s} -> {s}\n", .{ base_text, href_text, written }, ); return err; };
// RFC 3986 §5.2.2: a reference that carries a scheme resolves to // itself, with only its dot segments removed. if (Uri.parse(alloc, href_text)) |href| { defer href.deinit(); if (href.scheme) |scheme| { try expect(clicked.scheme != null); try expectEqualStrings(scheme, clicked.scheme.?); try expectEqual(href.port, clicked.port); try expectEqual(href.fragment == null, clicked.fragment == null); } } else |_| {}}
test "fuzz: relativize is the inverse of click" { try std.testing.fuzz({}, fuzzRelativize, .{});}
fn fuzzRelativize(_: void, s: *Smith) anyerror!void { const alloc = backing;
var base_buf: [max_text]u8 = undefined; var target_buf: [max_text]u8 = undefined; const base_text = base_buf[0..s.sliceWeightedBytes(&base_buf, delimiters)]; const target_text = target_buf[0..s.sliceWeightedBytes(&target_buf, delimiters)];
const base = Uri.parse(alloc, base_text) catch return; defer base.deinit(); const target = Uri.parse(alloc, target_text) catch return; defer target.deinit();
// The contract: resolving the target directly and resolving the // reference computed for it have to arrive at the same place. const want = base.clickUri(alloc, target) catch |err| switch (err) { error.OutOfMemory => return err, else => return, }; defer want.deinit();
// Every option set on each input, rather than a generated one. // `Smith.value` reads eight bytes per 64 bits and yields the range // minimum for anything out of range, so a bool asked of random // input is false almost every time and the other three // combinations would never be reached. const option_sets = [_]Uri.RelativizeOptions{ .{}, .{ .network_path = true }, .{ .absolute_path = true }, .{ .network_path = true, .absolute_path = true }, }; for (option_sets) |opts| { const rel = try base.relativize(alloc, target, opts); defer rel.deinit();
const got = base.clickUri(alloc, rel) catch |err| switch (err) { error.OutOfMemory => return err, else => return, }; defer got.deinit();
expect(want.eql(got)) catch |err| { dump("base", base.parts()); dump("target", target.parts()); dump("relative", rel.parts()); dump("want", want.parts()); dump("got", got.parts()); return err; }; }}
// -- file paths ------------------------------------------------------------
/// The bytes a *path* parser has opinions about: both separators, the colon/// and bar of a drive specification, the dot of a dot segment, and a handful/// of payload bytes -- one of which is not ASCII, since a POSIX path is bytes/// rather than text.const path_bytes: []const Weight = &.{ .value(u8, ' ', 2), .value(u8, '#', 2), .value(u8, '%', 3), .value(u8, '.', 4), .value(u8, '/', 10), .value(u8, ':', 6), .value(u8, '?', 2), .value(u8, 'C', 3), .value(u8, '\\', 8), .rangeAtMost(u8, 'a', 'c', 3), .value(u8, '|', 3), .value(u8, 0xff, 1),};
test "fuzz: a filesystem path survives the round trip through a file URI" { try std.testing.fuzz({}, fuzzFilePath, .{});}
fn fuzzFilePath(_: void, s: *Smith) anyerror!void { const alloc = backing;
var buf: [max_text]u8 = undefined; const path = buf[0..s.sliceWeightedBytes(&buf, path_bytes)];
// Both platforms on every input, for the same reason the // relativize target uses every option set: `Smith.value` yields a // range's minimum for anything out of range, so a generated enum // would be `.posix` almost every time. for ([_]Uri.FileOptions{ .{ .platform = .posix }, .{ .platform = .windows } }) |opts| { const u = Uri.fromPath(alloc, path, opts) catch |err| switch (err) { error.OutOfMemory => return err, // A relative path, or one no `file:` URI can spell. else => continue, }; defer u.deinit();
// The URI has to survive being written down and read back, // which is the trip that actually happens to one. const text = try u.toText(alloc, .{}); defer alloc.free(text); const reparsed = try Uri.parse(alloc, text); defer reparsed.deinit(); expect(u.eql(reparsed)) catch |err| { std.debug.print("path={s} text={s}\n", .{ path, text }); dump("built", u.parts()); dump("reparsed", reparsed.parts()); return err; };
const back = try u.toPath(alloc, opts); defer alloc.free(back);
// A POSIX path is a split and a join, so nothing may change. // A Windows path is canonicalised -- both separators go in // and only `\` comes out -- so what has to hold there is that // converting again changes nothing more. if (opts.platform == .posix) { try expectEqualStrings(path, back); } else { const again = try Uri.fromPath(alloc, back, opts); defer again.deinit(); const twice = try again.toPath(alloc, opts); defer alloc.free(twice); try expectEqualStrings(back, twice); try expect(u.eql(again)); } }}
// -- percent-encoding ------------------------------------------------------
test "fuzz: percent-encoding round-trips any byte string" { try std.testing.fuzz({}, fuzzPercent, .{});}
fn fuzzPercent(_: void, s: *Smith) anyerror!void { const alloc = backing;
var buf: [max_text]u8 = undefined; const raw = buf[0..s.slice(&buf)];
// Every component's character set, so that a set which wrongly // admits `%` or a delimiter shows up here. const sets = [_]*const percent.CharSet{ &percent.scheme, &percent.username, &percent.password, &percent.host, &percent.segment, &percent.segment_nc, &percent.query_key, &percent.query_value, &percent.fragment, }; const set = sets[s.index(sets.len)]; const form: percent.Form = s.value(percent.Form);
var aw: std.Io.Writer.Allocating = .init(alloc); defer aw.deinit(); try percent.encodeForm(&aw.writer, raw, set, form); const encoded = aw.written();
// Strict decoding: encoding must never emit a `%` that is not the // start of a well-formed escape. const decoded = percent.decode(alloc, encoded, true) catch |err| { std.debug.print("\nstrict decode of {s} failed\n", .{encoded}); return err; }; defer alloc.free(decoded);
expectEqualSlices(u8, raw, decoded) catch |err| { std.debug.print("\nround-trip changed bytes via {s}\n", .{encoded}); return err; };}
test "fuzz: lenient decoding accepts anything and never grows" { try std.testing.fuzz({}, fuzzPercentLenient, .{});}
fn fuzzPercentLenient(_: void, s: *Smith) anyerror!void { const alloc = backing;
var buf: [max_text]u8 = undefined; const text = buf[0..s.sliceWeightedBytes(&buf, delimiters)];
const lenient = try percent.decode(alloc, text, false); defer alloc.free(lenient); try expect(lenient.len <= text.len);
// Strict decoding differs only by rejecting a malformed escape, so // whenever it succeeds it has to agree byte for byte. if (percent.decode(alloc, text, true)) |strict| { defer alloc.free(strict); try expectEqualSlices(u8, lenient, strict); } else |err| try expectEqual(error.InvalidPercentEncoding, err);}
// -- Punycode --------------------------------------------------------------
test "fuzz: Punycode round-trips any label" { try std.testing.fuzz({}, fuzzPunycode, .{});}
fn fuzzPunycode(_: void, s: *Smith) anyerror!void { const alloc = backing;
var cps: [16]u21 = undefined; const n = s.index(cps.len + 1); for (cps[0..n]) |*cp| { const v = s.valueRangeAtMost(u21, 0, 0x10FFFF); // Surrogates are not code points; Punycode is defined over // scalar values, and `encode` may not be handed one. cp.* = if (v >= 0xD800 and v <= 0xDFFF) 0xFFFD else v; } const input = cps[0..n];
const encoded = punycode.encode(alloc, input) catch |err| switch (err) { // RFC 3492 §6.4 requires rejecting arithmetic that overflows. error.Overflow => return, error.OutOfMemory => return err, }; defer alloc.free(encoded);
const decoded = punycode.decode(alloc, encoded) catch |err| { std.debug.print("\ndecoding {s} failed\n", .{encoded}); return err; }; defer alloc.free(decoded);
expectEqualSlices(u21, input, decoded) catch |err| { std.debug.print("\nPunycode round-trip changed: {s}\n", .{encoded}); return err; };}
test "fuzz: Punycode decoding rejects rather than misbehaves" { try std.testing.fuzz({}, fuzzPunycodeDecode, .{});}
fn fuzzPunycodeDecode(_: void, s: *Smith) anyerror!void { const alloc = backing;
// The basic code points a Punycode label is written in, plus a few // bytes that have no business being there. const label_bytes: []const Weight = &.{ .rangeAtMost(u8, '0', '9', 4), .rangeAtMost(u8, 'a', 'z', 4), .value(u8, '-', 6), .value(u8, 'A', 1), .value(u8, 0x80, 1), };
var buf: [max_text]u8 = undefined; const text = buf[0..s.sliceWeightedBytes(&buf, label_bytes)];
const decoded = punycode.decode(alloc, text) catch |err| switch (err) { error.InvalidInput, error.Overflow => return, error.OutOfMemory => return err, }; defer alloc.free(decoded);
// Anything it does accept must be code points, and must survive // being encoded again -- decoding is the inverse of encoding, so // the two have to agree on which labels exist. for (decoded) |cp| { try expect(cp <= 0x10FFFF); try expect(cp < 0xD800 or cp > 0xDFFF); }
const encoded = punycode.encode(alloc, decoded) catch |err| switch (err) { error.Overflow => return, error.OutOfMemory => return err, }; defer alloc.free(encoded);
const again = try punycode.decode(alloc, encoded); defer alloc.free(again); try expectEqualSlices(u21, decoded, again);}
// -- hand-built components -------------------------------------------------
/// Valid address literals, which have to be handed to `Components` already/// well-formed: the parser validates them and the formatter writes them/// through unchanged.const ipv6_literals = [_][]const u8{ "::1", "::", "2001:db8::1", "2001:0db8:0000:0000:0000:0000:0000:0001", "::ffff:192.0.2.1", "fe80::1%25eth0", "v7.plan9",};
fn genBytes(s: *Smith, alloc: Allocator, max: usize) ![]const u8 { var buf: [24]u8 = undefined; const n = s.sliceWeightedBytes(buf[0..max], delimiters); return alloc.dupe(u8, buf[0..n]);}
fn genOptBytes(s: *Smith, alloc: Allocator, max: usize) !?[]const u8 { if (s.value(bool)) return null; return try genBytes(s, alloc, max);}
/// Build a `Components` directly, the way a caller assembling a URI by hand/// would -- including values the parser can never produce, such as a path/// segment holding a literal `/` or a host holding an `@`.////// Generation stays inside the invariants `format.write` documents, since/// those are preconditions rather than things to discover:////// * a scheme has to be a scheme, or writing it escapes the offending byte/// and the result no longer parses as one;/// * userinfo and a port belong to an authority, so they imply a host;/// * a password without a username would be written `:pw@`, which reads/// back as an empty username rather than none;/// * with no authority the path may not begin with `/`, which would be read/// back as rooted, nor with `//`, which would be read as an authority;/// * `rooted` is only written when a segment follows it, so an empty path/// cannot carry it -- parsing `/` gives one empty segment, not none;/// * and a lone `?` with an empty key writes an empty query string, which/// reads back as no parameters.fn genComponents(s: *Smith, alloc: Allocator) !Components { var c: Components = .{};
if (!s.value(bool)) { var buf: [4]u8 = undefined; buf[0] = 'a' + @as(u8, @intCast(s.index(26))); const rest = s.sliceWeightedBytes(buf[1..], &.{ .rangeAtMost(u8, '0', '9', 2), .rangeAtMost(u8, 'a', 'z', 3), .value(u8, '+', 1), .value(u8, '-', 1), .value(u8, '.', 1), }); c.scheme = try alloc.dupe(u8, buf[0 .. 1 + rest]); }
const has_authority = s.value(bool); if (has_authority) { c.host = switch (s.index(3)) { 0 => host: { const name = try genBytes(s, alloc, 8); // Match what the parser does with the same text: an authority // that reads as a dotted quad is an address, not a name. break :host if (z46.Ipv4Address.isValid(name)) Host{ .ipv4 = name } else Host{ .hostname = name }; }, 1 => .{ .ipv4 = try std.fmt.allocPrint(alloc, "{d}.{d}.{d}.{d}", .{ s.value(u8), s.value(u8), s.value(u8), s.value(u8), }) }, else => .{ .ipv6 = ipv6_literals[s.index(ipv6_literals.len)] }, }; c.username = try genOptBytes(s, alloc, 6); if (c.username != null) c.password = try genOptBytes(s, alloc, 6); if (!s.value(bool)) c.port = s.value(u16); }
var path = try alloc.alloc([]const u8, s.index(4)); for (path) |*seg| seg.* = try genBytes(s, alloc, 6);
// With no authority a path that begins with an empty segment is written // with a leading `/` and read back as rooted, and two of them would be // read back as an authority -- which is what `format.write` asserts // against. A single empty segment is fine: it *is* the leading `/`. if (!has_authority) { while (path.len > 1 and path[0].len == 0) path = path[1..]; } c.path = path;
c.rooted = if (path.len == 0) // The leading `/` is only written when a segment follows it, so with // no path at all nothing in the text can carry `rooted`. false else if (has_authority or (path.len == 1 and path[0].len == 0)) // An authority has to be followed by a `/` before the first segment, // and a lone empty segment is written as that same `/`. true else s.value(bool);
const q = s.index(4); const query = try alloc.alloc(QueryParam, q); for (query) |*param| { param.key = try genBytes(s, alloc, 6); param.value = try genOptBytes(s, alloc, 6); } c.query = query; if (q == 1 and query[0].key.len == 0 and query[0].value == null) c.query = &.{};
c.fragment = try genOptBytes(s, alloc, 6); return c;}
/// Print every field of a `Components`, so that a failure says which one/// moved rather than only which text it moved through.fn dump(label: []const u8, c: Components) void { std.debug.print("{s}: scheme={?s} username={?s} password={?s} host=", .{ label, c.scheme, c.username, c.password, }); if (c.host) |h| { std.debug.print("{t}({s})", .{ std.meta.activeTag(h), h.text() }); } else std.debug.print("null", .{}); std.debug.print(" port={?d} rooted={} path={{", .{ c.port, c.rooted }); for (c.path) |seg| std.debug.print("{s}|", .{seg}); std.debug.print("}} query={{", .{}); for (c.query) |q| std.debug.print("{s}={?s}|", .{ q.key, q.value }); std.debug.print("}} fragment={?s}\n", .{c.fragment});}
test "fuzz: hand-built components round-trip" { try std.testing.fuzz({}, fuzzComponents, .{});}
fn fuzzComponents(_: void, s: *Smith) anyerror!void { const alloc = backing;
var arena_state = std.heap.ArenaAllocator.init(alloc); defer arena_state.deinit(); const arena = arena_state.allocator();
const c = try genComponents(s, arena); const opts: Uri.TextOptions = .{ .with_password = true };
const text = try format_mod.toText(arena, c, opts); const parsed = Uri.parse(alloc, text) catch |err| { std.debug.print("\nparsing hand-built {s} failed\n", .{text}); return err; }; defer parsed.deinit();
expect(c.eql(parsed.parts())) catch |err| { std.debug.print("\nhand-built components changed via {s}\n", .{text}); dump("built ", c); dump("parsed", parsed.parts()); return err; }; try expectEqual(c.hash(), parsed.hash());
const again = try parsed.toText(arena, opts); expectEqualStrings(text, again) catch |err| { std.debug.print("\nunstable output from hand-built {s}\n", .{text}); return err; };}
// -- LDAP URLs -------------------------------------------------------------
/// What an RFC 4516 parser cares about, which is not quite what an RFC 3986/// one does: `?` separates the four positional sections rather than/// introducing a query, `,` separates attributes and extensions, `!` marks an/// extension critical, and `(`, `)`, `&`, `|`, `*` and `=` make up the filter/// language sitting inside the third of them.const ldap_delimiters: []const Weight = &.{ .value(u8, '?', 10), .value(u8, '%', 6), .value(u8, '/', 5), .value(u8, ',', 5), .value(u8, ':', 4), .value(u8, '=', 4), .value(u8, '!', 3), .rangeAtMost(u8, '(', '*', 3), // ( ) * .value(u8, '&', 3), .value(u8, '|', 3), .value(u8, '@', 2), .value(u8, '#', 2), .value(u8, '[', 2), .value(u8, ']', 2), .value(u8, '.', 2), .value(u8, '-', 2), // Payload: hex digits so `%XX` sometimes decodes, the letters that spell // `base`, `one` and `sub`, a space, and a byte that is not ASCII. .rangeAtMost(u8, '0', '9', 3), .rangeAtMost(u8, 'a', 'f', 3), .value(u8, 'n', 2), .value(u8, 'o', 2), .value(u8, 's', 2), .value(u8, 'u', 2), .value(u8, 'z', 1), .value(u8, 'S', 1), .value(u8, ' ', 1), .value(u8, 0xff, 1),};
/// The same property as `checkRoundTrip`, for `ldap.Url`: what was parsed/// survives being written and read back, and the second write is a fixed/// point.fn checkLdapRoundTrip(text: []const u8) !void { const alloc = backing;
const a = LdapUrl.parse(alloc, text) catch |err| switch (err) { // Every parse error is a documented rejection of malformed input. error.NotAnLdapUrl, error.MissingAuthority, error.UnexpectedUserinfo, error.InvalidScope, error.EmptyAttributeDescription, error.EmptyExtensionType, error.ExtraQuestionMark, error.InvalidScheme, error.InvalidAuthority, error.UnterminatedIPv6Literal, error.InvalidPort, error.InvalidIPv6Literal, error.InvalidPercentEncoding, => return, error.OutOfMemory => return err, }; defer a.deinit();
const once = try a.toText(alloc); defer alloc.free(once);
const b = LdapUrl.parse(alloc, once) catch |err| { std.debug.print("\nre-parsing {s} (from {s}) failed\n", .{ once, text }); return err; }; defer b.deinit();
expect(a.eql(b)) catch |err| { std.debug.print("\ncomponents changed: {s} -> {s}\n", .{ text, once }); return err; };
const twice = try b.toText(alloc); defer alloc.free(twice); expectEqualStrings(once, twice) catch |err| { std.debug.print("\nunstable output from: {s}\n", .{text}); return err; };}
test "fuzz: parsing an LDAP URL round-trips" { try std.testing.fuzz({}, fuzzLdapUrl, .{});}
fn fuzzLdapUrl(_: void, s: *Smith) anyerror!void { // Generated text practically never begins with a scheme, and an // input rejected at its first byte exercises nothing, so the // scheme and its `//` are supplied and the budget goes on the // part that is peculiar to this parser. The other three rejection // paths -- a scheme that is not LDAP, a missing `//`, and a // userinfo -- are what the arbitrary-bytes target below reaches. const prefix = "ldap://"; var buf: [prefix.len + max_text]u8 = undefined; buf[0..prefix.len].* = prefix.*; const n = s.sliceWeightedBytes(buf[prefix.len..], ldap_delimiters); try checkLdapRoundTrip(buf[0 .. prefix.len + n]);}
test "fuzz: an LDAP URL parses from arbitrary bytes or is rejected" { try std.testing.fuzz({}, fuzzLdapBytes, .{});}
fn fuzzLdapBytes(_: void, s: *Smith) anyerror!void { var buf: [max_text]u8 = undefined; const n = s.slice(&buf); try checkLdapRoundTrip(buf[0..n]);}
// -- data URLs ---------------------------------------------------------------
/// What an RFC 2397 parser cares about: `;` between the media type, its/// parameters and `base64`, `=` inside a parameter, the `,` that ends the/// header, `#` before a fragment, `%` escapes -- and the base64 alphabet, with/// the `/`, `+` and `=` that a generic parser would read as structure.const data_delimiters: []const Weight = &.{ .value(u8, ';', 10), .value(u8, ',', 10), .value(u8, '%', 6), .value(u8, '=', 5), .value(u8, '/', 5), .value(u8, '+', 4), .value(u8, '#', 2), .value(u8, '\n', 1), .value(u8, ' ', 1), // Payload: hex digits so `%XX` sometimes decodes, and the letters that // spell `base64`, in both cases. .rangeAtMost(u8, '0', '9', 3), .rangeAtMost(u8, 'a', 'f', 3), .rangeAtMost(u8, 'A', 'F', 2), .value(u8, 's', 2), .value(u8, 'S', 1), .value(u8, 'x', 1), .value(u8, 0xff, 1),};
/// The same property as `checkRoundTrip`, for `data.Url`: what was parsed/// survives being written and read back, and the second write is a fixed/// point.fn checkDataRoundTrip(text: []const u8) !void { const alloc = backing;
const a = DataUrl.parse(alloc, text) catch |err| switch (err) { // Every parse error is a documented rejection of malformed input. error.NotADataUrl, error.MissingComma, error.InvalidParameter, error.InvalidBase64, error.InvalidPercentEncoding, => return, error.OutOfMemory => return err, }; defer a.deinit();
const once = try a.toText(alloc); defer alloc.free(once);
const b = DataUrl.parse(alloc, once) catch |err| { std.debug.print("\nre-parsing {s} (from {s}) failed\n", .{ once, text }); return err; }; defer b.deinit();
expect(a.eql(b)) catch |err| { std.debug.print("\ncomponents changed: {s} -> {s}\n", .{ text, once }); return err; };
const twice = try b.toText(alloc); defer alloc.free(twice); expectEqualStrings(once, twice) catch |err| { std.debug.print("\nunstable output from: {s}\n", .{text}); return err; };}
test "fuzz: parsing a data URL round-trips" { try std.testing.fuzz({}, fuzzDataUrl, .{});}
fn fuzzDataUrl(_: void, s: *Smith) anyerror!void { // The scheme is supplied, as for LDAP: an input rejected at its first // byte exercises nothing, and the arbitrary-bytes target below is the // one that reaches the other scheme. const prefix = "data:"; var buf: [prefix.len + max_text]u8 = undefined; buf[0..prefix.len].* = prefix.*; const n = s.sliceWeightedBytes(buf[prefix.len..], data_delimiters); try checkDataRoundTrip(buf[0 .. prefix.len + n]);}
test "fuzz: a data URL parses from arbitrary bytes or is rejected" { try std.testing.fuzz({}, fuzzDataBytes, .{});}
fn fuzzDataBytes(_: void, s: *Smith) anyerror!void { var buf: [max_text]u8 = undefined; const n = s.slice(&buf); try checkDataRoundTrip(buf[0..n]);}
// -- DNS stamps -------------------------------------------------------------
/// The bytes a stamp is made of: the eight protocol identifiers, the small/// lengths a length prefix holds, the high bit a `VLP` continuation sets, and/// the punctuation that appears inside an address or a path.const stamp_bytes: []const Weight = &.{ // The protocol byte, which the first of these decides. Eight of 256 // otherwise, which would leave this searching the base64 decoder rather // than the eight readers behind it. .rangeAtMost(u8, 0x00, 0x05, 10), .value(u8, 0x81, 6), .value(u8, 0x85, 4), // Lengths a length prefix plausibly holds, and the high bit a `VLP` // continuation sets. .rangeAtMost(u8, 0x00, 0x10, 6), .value(u8, 0x20, 4), .value(u8, 0x80, 4), .value(u8, 0xff, 2), // What an address, a hostname or a path is made of. .value(u8, '.', 3), .value(u8, ':', 3), .value(u8, '/', 3), .rangeAtMost(u8, '0', '9', 2), .rangeAtMost(u8, 'a', 'z', 2),};
/// The one property worth stating about a stamp: what comes out of `parse` is/// what `toText` writes back, and writing is a fixed point rather than merely/// convergent.////// Rejections are listed rather than caught wholesale, so a *new* error tag in/// `stamp.Error` fails this test until somebody decides it is a rejection and/// says so here.fn checkStampRoundTrip(text: []const u8) !void { const alloc = backing;
const a = Stamp.parse(alloc, text) catch |err| switch (err) { error.NotAStamp, error.InvalidBase64, error.UnknownProtocol, error.Truncated, error.TrailingBytes, error.InvalidPublicKey, => return, error.OutOfMemory => return err, }; defer a.deinit();
const once = try a.toText(alloc); defer alloc.free(once);
const b = Stamp.parse(alloc, once) catch |err| { std.debug.print("\nre-parsing {s} (from {s}) failed\n", .{ once, text }); return err; }; defer b.deinit();
expect(a.eql(b)) catch |err| { std.debug.print("\nfields changed: {s} -> {s}\n", .{ text, once }); return err; };
const twice = try b.toText(alloc); defer alloc.free(twice); expectEqualStrings(once, twice) catch |err| { std.debug.print("\nunstable output from: {s}\n", .{text}); return err; };}
test "fuzz: a stamp round-trips from base64url of arbitrary bytes" { try std.testing.fuzz({}, fuzzStamp, .{});}
fn fuzzStamp(_: void, s: *Smith) anyerror!void { // The bytes are what a stamp is; the base64 is only how it travels, // and generating text directly would spend the budget on inputs // that fail to decode. The first byte decides the protocol, so it // is weighted towards the eight that mean something -- 8 of 256 // otherwise, which would leave this searching the decoder rather // than the eight readers behind it. var body: [max_text]u8 = undefined; const n = s.sliceWeightedBytes(&body, stamp_bytes); if (n == 0) return;
var buf: [stamp.prefix.len + max_text * 2]u8 = undefined; buf[0..stamp.prefix.len].* = stamp.prefix.*; const encoder = std.base64.url_safe_no_pad.Encoder; const encoded = encoder.encode(buf[stamp.prefix.len..], body[0..n]); try checkStampRoundTrip(buf[0 .. stamp.prefix.len + encoded.len]);}
test "fuzz: stamp text either parses or is rejected" { try std.testing.fuzz({}, fuzzStampText, .{});}
fn fuzzStampText(_: void, s: *Smith) anyerror!void { // Arbitrary text, which is what reaches `NotAStamp` and // `InvalidBase64` -- the two rejections the target above never // provokes, because it always writes a well-formed prefix and a // well-formed body. var buf: [max_text]u8 = undefined; const n = s.slice(&buf); try checkStampRoundTrip(buf[0..n]);}
// -- the table the standalone driver runs ------------------------------------//// Zig's own fuzzer is what these targets are written for, and in 0.16.0 it// cannot steer: the table of program counters comes out empty however the// modules are built, so `zig build test --fuzz=N` searches blindly and then// fails on the coverage report. `tools/fuzz.zig` is a loop of our own that runs// the same targets against input it makes up, with a corpus of real URIs,// paths, LDAP URLs and stamps in place of the coverage feedback -- and it// counts what it did, which the other one cannot.
pub const Target = struct { name: []const u8, run: *const fn (input: []const u8) anyerror!void, /// Inputs worth mutating: real text of the kind this target parses. This is /// the whole of what stands in for coverage, and it is most of the value -- /// a URI of random bytes stops parsing at its first byte, and a stamp of /// them is refused by its protocol byte, so starting from something that /// already parses is what gets past the front door. corpus: []const []const u8 = &.{}, /// How many length-prefixed chunks this target reads before it asks for /// anything else. Zero for the ones that ask only for numbers. slices: u8 = 1, /// The buffer a chunk is read into. /// /// `Smith.slice` answers a length larger than its buffer with an *empty* /// slice rather than a truncated one, so a generator that does not know /// this number hands the target nothing at all -- and does it silently, the /// run reporting millions of iterations that all parsed the empty string. content_max: usize = max_text,};
/// Wraps one of the `fuzz*` functions above so that it takes raw bytes.fn Driven(comptime one: fn (void, *Smith) anyerror!void) type { return struct { fn run(input: []const u8) anyerror!void { var smith: Smith = .{ .in = input }; return one({}, &smith); } };}
/// References of every shape RFC 3986 distinguishes, which is what the parser/// branches on: absolute and relative, with and without an authority, every kind/// of host, an empty port, a zone identifier, and the dot segments.////// Spelled in the alphabet above, and that is not a stylistic choice./// `Smith.sliceWeightedBytes` copies a seed byte only when the weights list it/// and replaces every other byte with the *first* weight's -- so a seed written/// as `https://example.com` reaches the parser as `%%%%%://%%a%%%e.%%%`, keeping/// its shape and losing everything else. A corpus for a weighted target is/// therefore written in that target's own letters; `uri-bytes` below reads the/// same shapes literally, because it asks for a plain `slice`.const uri_seeds = [_][]const u8{ "abc://ba.ce/a/b?c=1#d", "abc://face:dead@ba.ce:8080/a/b/../c", "abc://[2001:db8::1]:8080/v6", "abc://[fe80::1%25eff]/zone", "//ba.ce/a/b", "/a/b/c", "ba/ce", "../a/b", "?a=1&b=2", "#fade", "abc:def:1234", "abc:ba@ce.ef", "abc:///a/b", "ABC://BA.CE:443/./a/../b%2Fc", "abc://ba.ce:/a", "abc://[v1.fe]/", "a:b", ":", "",};
/// Whole references as text, for the target that reads bytes rather than an/// alphabet: the same shapes, spelled the way anybody would actually write/// them.const uri_text_seeds = [_][]const u8{ "https://example.com/path?a=1#top", "http://user:pass@example.com:8080/a/b/../c", "http://[2001:db8::1]:8080/v6", "//example.com/protocol-relative", "/just/a/path", "relative/reference", "urn:ietf:rfc:3986", "mailto:jeff@example.com", "file:///etc/hosts", "HTTPS://EXAMPLE.COM:443/./a/../b%2Fc", "a:b", ":", "",};
/// Paths of both syntaxes, since the target converts every input twice -- and/// in `path_bytes`' own alphabet, which is why the only letters here are `a`,/// `b`, `c` and the drive letter `C`.const path_seeds = [_][]const u8{ "/ab/ca", "/a/b c/%ab", "/abc/", "//ab//ca", "ab/ca", "C:\\ab\\ca", "C:/ab\\ca", "\\\\ab\\ca\\bc", "C:a", "/a/../b", "/", "",};
/// Byte strings with the two things percent-encoding has opinions about: a/// `%` that introduces an escape, and one that does not.const percent_seeds = [_][]const u8{ "a b", "%41%42", "%2F%2f", "%", "%2", "%zz", "100% pure", "\x00\xff\x7f", "unreserved-._~", "",};
/// Labels a Punycode decoder has to take apart, and a few that are nearly one.const punycode_seeds = [_][]const u8{ "bcher-kva", "zckzah", "3y-", "a-", "-", "--", "0", "xn--", "99999999999999999999", "",};
/// What follows `ldap://` in a URL: the four positional sections, the filter/// language, and the extensions -- in `ldap_delimiters`' alphabet, which is why/// the words are spelled out of the few letters it carries.const ldap_seeds = [_][]const u8{ "ba.ce/dc=one,dc=ca?cn,badd?sub?(&(cn=abc)(sn=dea))", "ba.ce:389/dc=a?cn?base?(cn=*)", "ba.ce/dc=a?a,b?one?(a=b)?!ex=1,ba=2", "ba.ce/", "/", "",};
/// Whole URLs, including the three rejections the target above never reaches:/// a scheme that is not LDAP, a missing `//`, and a userinfo.const ldap_url_seeds = [_][]const u8{ "ldap://host/dn", "ldaps://host:636/dc=example,dc=com?cn?sub?(cn=*)", "ldapi://%2Fvar%2Frun%2Fldapi/", "ldap://user@host/", "ldap:host/", "http://not-ldap/", "ldap://", "",};
/// What follows `data:` in a URL: media types with and without parameters,/// base64 with and without padding, and escapes in each part.const data_seeds = [_][]const u8{ ",A%20brief%20note", "image/svg+xml;base64,PHN2Zy8+", ";charset=utf-8;note=a%2Cb,h%C3%A9", "application/octet-stream;base64,//79#frag", "text/plain;base64,aGVs\nbG8", ";base64,", ",", "",};
/// Whole URLs, including the rejections the target above never reaches: a/// scheme that is not `data`, and no scheme at all.const data_url_seeds = [_][]const u8{ "data:,hello", "DATA:text/plain;charset=US-ASCII,hi", "data:image/png;base64,iVBORw0KGgo=", "http://not-data/", "data", "",};
/// The *bytes* a stamp is made of rather than the base64 it travels as, since/// that is what this target is handed: a protocol byte, a properties word, and/// the length-prefixed fields behind them.const stamp_body_seeds = [_][]const u8{ // Plain DNS at 192.0.2.1. "\x00" ++ "\x07\x00\x00\x00\x00\x00\x00\x00" ++ "\x09" ++ "192.0.2.1", // A DNSCrypt relay, which is the one layout with no properties word. "\x81" ++ "\x12" ++ "95.216.149.154:443", // DNS over TLS with no address, one pinned hash, and a hostname. "\x03" ++ "\x07\x00\x00\x00\x00\x00\x00\x00" ++ "\x00" ++ "\x00" ++ "\x0f" ++ "dot.example.com", // DNS over HTTPS, which is the longest shape: hashes, hostname, path and // bootstrap resolvers. "\x02" ++ "\x07\x00\x00\x00\x00\x00\x00\x00" ++ "\x07" ++ "1.0.0.1" ++ "\x00" ++ "\x0f" ++ "doh.example.com" ++ "\x0a" ++ "/dns-query", // A protocol byte nobody has assigned, and one field too many. "\x06" ++ "\x07\x00\x00\x00\x00\x00\x00\x00" ++ "\x00", "\x00" ++ "\x07\x00\x00\x00\x00\x00\x00\x00" ++ "\x01" ++ "x" ++ "trailing", "",};
/// Stamps as text, short enough to survive this target's own buffer.const stamp_text_seeds = [_][]const u8{ "sdns://gRI5NS4yMTYuMTQ5LjE1NDo0NDM", "sdns://AAcAAAAAAAAACTE5Mi4wLjIuMQ", "sdns://AAcAAAAAAAAACTE5Mi4wLjIuMQ==", "sdns://", "sdns://!!!", "http://example.com/", "",};
const base_targets = [_]Target{ .{ .name = "uri", .run = Driven(fuzzDelimitedText).run, .corpus = &uri_seeds }, .{ .name = "uri-bytes", .run = Driven(fuzzArbitraryText).run, .corpus = &uri_text_seeds }, .{ .name = "iri", .run = Driven(fuzzIriForm).run, .corpus = &uri_seeds }, // Five booleans after the text, which is why the generator writes a tail of // small numbers rather than of random bytes: a `bool` out of range is // `false`, so random bytes would fuzz one option set out of thirty-two. .{ .name = "normalize", .run = Driven(fuzzNormalize).run, .corpus = &uri_seeds }, .{ .name = "click", .run = Driven(fuzzClick).run, .corpus = &uri_seeds, .slices = 2 }, .{ .name = "relativize", .run = Driven(fuzzRelativize).run, .corpus = &uri_seeds, .slices = 2 }, .{ .name = "file-path", .run = Driven(fuzzFilePath).run, .corpus = &path_seeds }, .{ .name = "percent", .run = Driven(fuzzPercent).run, .corpus = &percent_seeds }, .{ .name = "percent-lenient", .run = Driven(fuzzPercentLenient).run, .corpus = &percent_seeds }, // Neither Punycode target nor the components one reads a chunk: they ask // for a count and then for code points or fields, so an input of // length-prefixed text would be read as numbers and yield the minimum of // every range. .{ .name = "punycode", .run = Driven(fuzzPunycode).run, .slices = 0 }, .{ .name = "punycode-decode", .run = Driven(fuzzPunycodeDecode).run, .corpus = &punycode_seeds }, .{ .name = "components", .run = Driven(fuzzComponents).run, .slices = 0 }, .{ .name = "ldap", .run = Driven(fuzzLdapUrl).run, .corpus = &ldap_seeds }, .{ .name = "ldap-bytes", .run = Driven(fuzzLdapBytes).run, .corpus = &ldap_url_seeds }, .{ .name = "data", .run = Driven(fuzzDataUrl).run, .corpus = &data_seeds }, .{ .name = "data-bytes", .run = Driven(fuzzDataBytes).run, .corpus = &data_url_seeds }, .{ .name = "stamp", .run = Driven(fuzzStamp).run, .corpus = &stamp_body_seeds }, .{ .name = "stamp-text", .run = Driven(fuzzStampText).run, .corpus = &stamp_text_seeds },};
/// The targets the driver runs, which is everything this build has: the four/// Unicode ones exist only with `-Dunicode=true`, and naming them in a build/// without the tables would not compile.pub const all: []const Target = if (build_options.unicode) &(base_targets ++ @import("fuzz_unicode.zig").targets)else &base_targets;