Skip to content
Agentmart
Submit a tool

nim-fuzzing

Set up and run libFuzzer-based fuzz targets for Nim code, including harness wiring, compilation flags, corpus management, structure-aware mutators, and crash…

Skill by Vyrnexis

IndexedMIT★ 4
Write a review

Chalk Labs

Need help deploying nim-fuzzing?

Chalk Labs sets up agents like this inside real teams: connected to your tools, tested on your data, with a human in the loop where it matters.

Book a call

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/vyrnexis-nim-fuzzing

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Set up and run libFuzzer-based fuzz targets for Nim code, including harness wiring, compilation flags, corpus management, structure-aware mutators, and crash triage. Use when adding fuzzing to a Nim project, building a fuzz harness for a parser/protocol/format handler, or reproducing and minimizing a fuzzer-found crash.

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/nim-fuzzing

What's inside

Skill name
nim-fuzzing
Description
Set up and run libFuzzer-based fuzz targets for Nim code, including harness wiring, compilation flags, corpus management, structure-aware mutators, and crash triage. Use when adding fuzzing to a Nim project, building a fuzz harness for a parser/protocol/format handler, or reproducing and minimizing a fuzzer-found crash.
License
MIT
Instructions
356 lines in SKILL.md · view on GitHub

Files (4)

  • SKILL.md
  • protocol_fuzzer.md · references/
  • simple_byte_target.md · references/
  • structure_aware_fuzzing.md · references/

SKILL.md (first lines)

# Nim Fuzzing

This skill covers wiring code to libFuzzer — harness structure, compilation, corpus, mutators, and crash triage. It does NOT cover writing the code under test.

# Rules

## Harness structure: the two required procs

Every Nim fuzz target needs these two exported procs:

```nim
proc initialize(): cint {.cdecl, exportc: "LLVMFuzzerInitialize".} =
  {.emit: "N_CDECL(void, NimMain)(void); NimMain();".}

proc testOneInput(data: ptr UncheckedArray[byte], len: int): cint {.
    cdecl, exportc: "LLVMFuzzerTestOneInput", raises: [].} =
  result = 0
  # exercise code under test with data[0..<len]
```

`initialize` is called once at startup. It bootstraps Nim's runtime via
`NimMain()`. Without it the target will segfault before any inputs are tested.

`testOneInput` is called by libFuzzer with a raw byte buffer. It must return
0. Use `raises: []` — any uncaught exception will crash the fuzzer process,
which is treated as a finding.

## Minimum working example

```nim
proc fuzzMe(data: openArray[byte]): bool =
  result = data.len >= 3 and
    data[0].char == 'F' and
    data[1].char == 'U' and
    data[2].char == 'Z' and
    data[3].char == 'Z' # out-of-bounds when data.len == 3

proc initialize(): cint {.cdecl, exportc: "LLVMFuzzerInitialize".} =
  {.emit: "N_CDECL(void, NimMain)(void); NimMain();".}

proc testOneInput(data: ptr UncheckedArray[byte], len: int): cint {.
    cdecl, exportc: "LLVMFuzzerTestOneInput", raises: [].} =
  result = 0
  discard fuzzMe(data.toOpenArray(0, len-1))
```

## Data extraction patterns

How to convert `ptr UncheckedArray[byte]` + `len` to Nim types:

| Target format          | Extraction code |
|------------------------|-----------------|
| raw byte buffer        | `data.toOpenArray(0, len-1)` |
| string                 | `var s = newString(len); if len > 0: copyMem(addr s[0], data, len)` |
| seq[T] via copyMem     | `let n = len div sizeof(T); var s = newSeq[T](n); if n > 0: copyMem(addr s[0], data, n * sizeof(T))` |
| plain fixed-layout type | `if len >= sizeof(T): var value: T; copyMem(addr value, data, sizeof(T))` |

For the copyMem patterns, the fuzzer-provided buffer is a flat byte array.
Check the length before taking element addresses or copying bytes.

## Error handling in the harness

Compile fuzz targets with `--panics:on`. This turns `Defect` subtypes
(`IndexDefect`, `OverflowDefect`, `AssertionDefect`, etc.) into non-catchable
panics that immediately crash the process — which libFuzzer interprets as a
finding. You don't need a manual `except Defect` block.

`testOneInput` must have `raises: []`. Catch only specific expected error
types (e.g., `except ValueError`) and let everything else crash. Never use
`except Exception` — it catches `Defect` even with panics off, masking real
bugs. Bare `except` is equivalent to `except CatchableError` and does not
catch `Defect`.

```nim
proc testOneInput(data: ptr UncheckedArray[byte], len: int): cint {.
    cdecl, exportc: "LLVMFuzzerTestOneInput", raises: [].} =
  result = 0
  if len > 0:
    var input = newString(len)
    copyMem(addr input[0], data, len)
    try:
      parseMyFormat(input)
    except ValueError:
      discard          # expected rejection
  # Defects crash the process — no catch needed with --panics:on
```

## Compilation

### Build config file (recommended)

Name the config file `<harnessname>.nims` (e.g. `my_fuzzer.nims` for
`my_fuzzer.nim`) or `config.nims`.

```nim
--cc: clang
--panics: on
--define: noSignalHandler
--define: useMalloc
--noMain: on
--passC: "-fsanitize=fuzzer,address,undefined"
--passL: "-fsanitize=fuzzer,address,undefined"
--debugger: native
```

| Flag                   | Purpose |
|------------------------|---------|
| `--cc: clang`          | libFuzzer requires Clang. |
| `--panics: on`         | Defects crash the process immediately. |
| `--noMain: on`         | libFuzzer provides its own `main`. |
| `--define: noSignalHandler` | Prevents Nim's signal handler from masking crashes before ASan. |
| `--define: useMalloc`  | Uses C malloc so ASan tracks all allocations. |
| `--passC:"-fsanitize=fuzzer,address,undefined"` | Enables libFuzzer + ASan + UBSan. |
| `--passL:"-fsanitize=fuzzer,address,undefined"` | Links the sanitizer runtimes. |
| `--debugger: native`   | Embeds DWARF debug info in crash reports. |

## Corpus management

libFuzzer needs a corpus directory. Start with at least one seed input:

From Vyrnexis/nim-agent-template, MIT.

More from Vyrnexis/nim-agent-template

Signals

Stars
4
Forks
2
Open issues
0
Last commit (this folder)
Aug 20, 2026 (2 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from Vyrnexis

Done for you

Rather not set it up yourself?

Chalk Labs scopes, builds and runs agents for your team: the task audit, the eval harness, the integrations and the weekly ops report. Fixed scope, priced before we start.

See how we build AI agents →Read the case studies

Chalk Labs is a two-founder AI and growth studio. We build AI agents, CRMs and MVPs for Web3 and AI companies, and have shipped 50+ product and token launches.

launches shipped
50+
launches shipped
media placements
500+
media placements
founders on every account
2
founders on every account

Press we've placed: Forbes · CoinDesk · Decrypt · Cointelegraph · The Block

Rahil Jain, Co-founder, Chalk Labs. Ex-Goldman Sachs engineer. You talk to the person who builds it.

Get nim-fuzzing running in your business

Tell us what you want to automate. A founder replies within one working day with a plan, not a pitch deck.

Goes to the Chalk Labs founders, not the newsletter. Privacy

Need help deploying nim-fuzzing?

CallGet help
Cite this page

nim-fuzzing skill. Agent Mart. https://agentmart.dev/skills/vyrnexis-nim-fuzzing (last updated 2026-10-24)