CodeSampleX

Beispiel

github.com/quic-go/go-ossfuzz-seeds v0.1.0: Helper.Add

Verifiziertes Beispiel für golang github.com/quic-go/go-ossfuzz-seeds v0.1.0: Helper.Add. Der Vertrag lief auf go 1.26 · linux debian/x64 · docker und…

sha256:8f53ba8af150715939606787b9f4213de514fabd0ced280a1d07d97c1fc7a2a7

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go 1.26 go 1

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-09-05

Fall

HOW
Ziel
verify github.com/quic-go/go-ossfuzz-seeds.Helper.Add in pkg:golang/github.com/quic-go/go-ossfuzz-seeds@v0.1.0
Pakete
Symbole
  • github.com/quic-go/go-ossfuzz-seeds.Helper.Add
Umgebung
go 1.26.6
Erstellt
2026-09-05T13:34:19Z

Contract

  1. Helper.Add forwards seed arguments to testing.F without creating files when FUZZ_CORPUS_DIR is unset
  2. Helper.Add creates a corpus entry file in FUZZ_CORPUS_DIR when enabled
  3. Helper.Add uses the first 8 bytes of SHA-256 hash in hex as the corpus filename
  4. Helper.Add writes corpus files with 0644 permissions
  5. Helper.Add writes binary content matching OSS-Fuzz corpus entry serialization for mixed arguments
  6. Helper.Add skips file creation when dynamic argument lengths exceed encoding capacity

Dateien

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

Quellartefakt herunterladen (tar.gz)

Quelltext

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify github.com/quic-go/go-ossfuzz-seeds.Helper.Add in pkg:golang/github.com/quic-go/go-ossfuzz-seeds@v0.1.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/quic-go/go-ossfuzz-seeds@v0.1.0
Demonstrate these symbols/APIs:
  - github.com/quic-go/go-ossfuzz-seeds.Helper.Add
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:1d68b5b58c1004764d70d108a506377ac5326cb3c172cf5bc6a3b0be7fd72305","contract":["Helper.Add forwards seed arguments to testing.F without creating files when FUZZ_CORPUS_DIR is unset","Helper.Add creates a corpus entry file in FUZZ_CORPUS_DIR when enabled","Helper.Add uses the first 8 bytes of SHA-256 hash in hex as the corpus filename","Helper.Add writes corpus files with 0644 permissions","Helper.Add writes binary content matching OSS-Fuzz corpus entry serialization for mixed arguments","Helper.Add skips file creation when dynamic argument lengths exceed encoding capacity"],"goal":"verify github.com/quic-go/go-ossfuzz-seeds.Helper.Add in pkg:golang/github.com/quic-go/go-ossfuzz-seeds@v0.1.0","kind":"HOW","packages":["pkg:golang/github.com/quic-go/go-ossfuzz-seeds@v0.1.0"],"schemaVersion":1,"symbols":["github.com/quic-go/go-ossfuzz-seeds.Helper.Add"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","compiler":"go","compilerVersion":"1.26.6","distro":"ubuntu","ecosystem":"golang","language":"go","languageVersion":"1.26.6","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/quic-go/go-ossfuzz-seeds@v0.1.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/quic-go/go-ossfuzz-seeds@v0.1.0","symbols":["github.com/quic-go/go-ossfuzz-seeds.Helper.Add"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require github.com/quic-go/go-ossfuzz-seeds v0.1.0
go.sum
github.com/quic-go/go-ossfuzz-seeds v0.1.0 h1:APacT+iIaNF6fd8AGEiN3bT/Jtkd2jz4v4TzM7MFjy0=
github.com/quic-go/go-ossfuzz-seeds v0.1.0/go.mod h1:3IOHRbJIc+L6YKMwfDtJAM9Vj9k0YY4muhuyUYk5tbk=
main.go
package main

import (
	"fmt"
	"os"
	"testing"

	ossfuzzseeds "github.com/quic-go/go-ossfuzz-seeds"
)

func main() {
	testing.Init()

	corpusDir := os.Getenv("FUZZ_CORPUS_DIR")
	if corpusDir == "" {
		corpusDir = "./corpus"
		os.Setenv("FUZZ_CORPUS_DIR", corpusDir)
		defer os.RemoveAll(corpusDir)
	}

	f := &testing.F{}
	h := ossfuzzseeds.New(f)

	// Demonstrate Helper.Add with both fixed-size and dynamic-size seed values
	h.Add(uint16(42), "example-seed", []byte("fuzz-payload"))

	fmt.Printf("Seed added to corpus directory %s\n", corpusDir)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/quic-go/go-ossfuzz-seeds.Helper.Add in pkg:golang/github.com/quic-go/go-ossfuzz-seeds@v0.1.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/quic-go/go-ossfuzz-seeds@v0.1.0"
  ],
  "symbols": [
    "github.com/quic-go/go-ossfuzz-seeds.Helper.Add"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.go
package main

import (
	"bytes"
	"crypto/sha256"
	"encoding/hex"
	"errors"
	"fmt"
	"os"
	"path/filepath"
	"testing"

	ossfuzzseeds "github.com/quic-go/go-ossfuzz-seeds"
)

func main() {
	testing.Init()

	if err := runContract(); err != nil {
		fmt.Fprintf(os.Stderr, "Contract failed: %v\n", err)
		os.Exit(1)
	}
	fmt.Println("All contract assertions passed.")
}

func runContract() error {
	// Assertion 1: Helper.Add forwards seed arguments to testing.F without creating files when FUZZ_CORPUS_DIR is unset
	{
		os.Unsetenv("FUZZ_CORPUS_DIR")
		f := &testing.F{}
		h := ossfuzzseeds.New(f)
		if h == nil {
			return errors.New("assertion 1 failed: New returned nil")
		}
		h.Add(uint8(42), "seed-no-corpus")
	}

	tmpDir, err := os.MkdirTemp("", "csx-add-contract-*")
	if err != nil {
		return fmt.Errorf("failed to create temp dir: %w", err)
	}
	defer os.RemoveAll(tmpDir)

	// Assertion 2: Helper.Add creates a corpus entry file in FUZZ_CORPUS_DIR when enabled
	corpusDir2 := filepath.Join(tmpDir, "corpus2")
	{
		os.Setenv("FUZZ_CORPUS_DIR", corpusDir2)
		defer os.Unsetenv("FUZZ_CORPUS_DIR")

		f := &testing.F{}
		h := ossfuzzseeds.New(f)
		h.Add(int32(100), "sample-seed")

		entries, err := os.ReadDir(corpusDir2)
		if err != nil {
			return fmt.Errorf("assertion 2 failed: ReadDir failed: %w", err)
		}
		if len(entries) != 1 {
			return fmt.Errorf("assertion 2 failed: expected 1 file, found %d", len(entries))
		}
	}

	// Assertion 3: Helper.Add uses the first 8 bytes of SHA-256 hash in hex as the corpus filename
	corpusDir3 := filepath.Join(tmpDir, "corpus3")
	{
		os.Setenv("FUZZ_CORPUS_DIR", corpusDir3)
		defer os.Unsetenv("FUZZ_CORPUS_DIR")

		f := &testing.F{}
		h := ossfuzzseeds.New(f)
		args := []any{uint64(999), "hash-filename-test"}
		h.Add(args...)

		expectedBytes, err := ossfuzzseeds.CorpusEntry(args...)
		if err != nil {
			return fmt.Errorf("assertion 3 failed: CorpusEntry serialization error: %w", err)
		}
		hash := sha256.Sum256(expectedBytes)
		expectedFilename := hex.EncodeToString(hash[:8])

		entries, err := os.ReadDir(corpusDir3)
		if err != nil || len(entries) != 1 {
			return fmt.Errorf("assertion 3 failed: expected 1 entry, got %v: %w", entries, err)
		}
		if entries[0].Name() != expectedFilename {
			return fmt.Errorf("assertion 3 failed: filename mismatch, got %s, want %s", entries[0].Name(), expectedFilename)
		}
		if len(entries[0].Name()) != 16 {
			return fmt.Errorf("assertion 3 failed: filename length should be 16, got %d", len(entries[0].Name()))
		}
	}

	// Assertion 4: Helper.Add writes corpus files with 0644 permissions
	corpusDir4 := filepath.Join(tmpDir, "corpus4")
	{
		os.Setenv("FUZZ_CORPUS_DIR", corpusDir4)
		defer os.Unsetenv("FUZZ_CORPUS_DIR")

		f := &testing.F{}
		h := ossfuzzseeds.New(f)
		h.Add(true, uint16(55))

		entries, err := os.ReadDir(corpusDir4)
		if err != nil || len(entries) != 1 {
			return fmt.Errorf("assertion 4 failed: expected 1 entry in %s: %w", corpusDir4, err)
		}
		info, err := entries[0].Info()
		if err != nil {
			return fmt.Errorf("assertion 4 failed: stat error: %w", err)
		}
		if info.Mode().Perm() != 0o644 {
			return fmt.Errorf("assertion 4 failed: expected mode 0644, got %v", info.Mode().Perm())
		}
	}

	// Assertion 5: Helper.Add writes binary content matching OSS-Fuzz corpus entry serialization for mixed arguments
	corpusDir5 := filepath.Join(tmpDir, "corpus5")
	{
		os.Setenv("FUZZ_CORPUS_DIR", corpusDir5)
		defer os.Unsetenv("FUZZ_CORPUS_DIR")

		f := &testing.F{}
		h := ossfuzzseeds.New(f)
		args := []any{uint8(3), int64(1000), "prefix", []byte{0xde, 0xad, 0xbe, 0xef}}
		h.Add(args...)

		expectedBytes, err := ossfuzzseeds.CorpusEntry(args...)
		if err != nil {
			return fmt.Errorf("assertion 5 failed: CorpusEntry serialization error: %w", err)
		}

		entries, err := os.ReadDir(corpusDir5)
		if err != nil || len(entries) != 1 {
			return fmt.Errorf("assertion 5 failed: expected 1 file, found %v: %w", entries, err)
		}
		content, err := os.ReadFile(filepath.Join(corpusDir5, entries[0].Name()))
		if err != nil {
			return fmt.Errorf("assertion 5 failed: ReadFile failed: %w", err)
		}
		if !bytes.Equal(content, expectedBytes) {
			return fmt.Errorf("assertion 5 failed: content mismatch, got %x, want %x", content, expectedBytes)
		}
	}

	// Assertion 6: Helper.Add skips file creation when dynamic argument lengths exceed encoding capacity
	corpusDir6 := filepath.Join(tmpDir, "corpus6")
	{
		os.Setenv("FUZZ_CORPUS_DIR", corpusDir6)
		defer os.Unsetenv("FUZZ_CORPUS_DIR")

		f := &testing.F{}
		h := ossfuzzseeds.New(f)
		// dynamicSizeWeights fails on lengths {1, 1, 100000}
		h.Add(make([]byte, 1), make([]byte, 1), make([]byte, 100000))

		entries, err := os.ReadDir(corpusDir6)
		if err != nil {
			return fmt.Errorf("assertion 6 failed: ReadDir failed: %w", err)
		}
		if len(entries) != 0 {
			return fmt.Errorf("assertion 6 failed: expected 0 files on unencodable dynamic lengths, found %d", len(entries))
		}
	}

	return nil
}

Ursprungs-Seeder

anonym