CodeSampleX

Ejemplo

github.com/klauspost/compress v1.19.1: zlib.ErrDictionary

Muestra verificada para golang github.com/klauspost/compress v1.19.1: zlib.ErrDictionary. El contrato se ejecutó en go 1.26 · linux debian/x64 · docker y…

sha256:f0a08ad38b37766137bc4b0469f37da7d06a11b23f25d4f3254f9928329a07d3

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 go

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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-10-11

Caso

HOW
Objetivo
verify github.com/klauspost/compress/zlib.ErrDictionary in pkg:golang/github.com/klauspost/compress@v1.19.1
Paquetes
Símbolos
  • github.com/klauspost/compress/zlib.ErrDictionary
Creado
2026-10-11T09:17:34Z

Contrato

  1. ErrDictionary is the sentinel error variable exported by zlib with message "zlib: invalid dictionary"
  2. NewReader returns ErrDictionary when decompressing a zlib stream that requires a preset dictionary
  3. NewReaderDict returns ErrDictionary when decompressing a stream with an incorrect preset dictionary
  4. Resetter.Reset returns ErrDictionary when resetting an existing reader with an incorrect dictionary for dictionary-compressed data
  5. NewReaderDict succeeds and does not return ErrDictionary when the correct preset dictionary is provided

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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/klauspost/compress/zlib.ErrDictionary in pkg:golang/github.com/klauspost/compress@v1.19.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/klauspost/compress@v1.19.1
Demonstrate these symbols/APIs:
  - github.com/klauspost/compress/zlib.ErrDictionary

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:de85638620af166e2a901a7eecf131842ec3403b8e670db73909dd8f1b8fb326","contract":["ErrDictionary is the sentinel error variable exported by zlib with message \"zlib: invalid dictionary\"","NewReader returns ErrDictionary when decompressing a zlib stream that requires a preset dictionary","NewReaderDict returns ErrDictionary when decompressing a stream with an incorrect preset dictionary","Resetter.Reset returns ErrDictionary when resetting an existing reader with an incorrect dictionary for dictionary-compressed data","NewReaderDict succeeds and does not return ErrDictionary when the correct preset dictionary is provided"],"goal":"verify github.com/klauspost/compress/zlib.ErrDictionary in pkg:golang/github.com/klauspost/compress@v1.19.1","kind":"HOW","packages":["pkg:golang/github.com/klauspost/compress@v1.19.1"],"schemaVersion":1,"symbols":["github.com/klauspost/compress/zlib.ErrDictionary"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/klauspost/compress@v1.19.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/klauspost/compress@v1.19.1","symbols":["github.com/klauspost/compress/zlib.ErrDictionary"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/klauspost/compress v1.19.1
go.sum
github.com/klauspost/compress v1.19.1 h1:VsB4HPswih7mmZ8WleSFQ75c/Ui1M4trX5oAsJnhSlk=
github.com/klauspost/compress v1.19.1/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
main.go
package main

import (
	"bytes"
	"errors"
	"fmt"
	"io"
	"os"

	"github.com/klauspost/compress/zlib"
)

func main() {
	dict := []byte("example-zlib-dictionary")
	payload := []byte("Demonstrating ErrDictionary error handling with klauspost/compress")

	var buf bytes.Buffer
	writer, err := zlib.NewWriterLevelDict(&buf, zlib.DefaultCompression, dict)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to create writer: %v\n", err)
		os.Exit(1)
	}
	if _, err := writer.Write(payload); err != nil {
		fmt.Fprintf(os.Stderr, "failed to write: %v\n", err)
		os.Exit(1)
	}
	if err := writer.Close(); err != nil {
		fmt.Fprintf(os.Stderr, "failed to close writer: %v\n", err)
		os.Exit(1)
	}

	// Attempt to read without providing the required dictionary
	compressedData := buf.Bytes()
	_, err = zlib.NewReader(bytes.NewReader(compressedData))
	if errors.Is(err, zlib.ErrDictionary) {
		fmt.Printf("Successfully caught expected error: %v\n", err)
	} else {
		fmt.Fprintf(os.Stderr, "expected zlib.ErrDictionary, got: %v\n", err)
		os.Exit(1)
	}

	// Now decompress successfully with the matching dictionary
	reader, err := zlib.NewReaderDict(bytes.NewReader(compressedData), dict)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to open reader with dictionary: %v\n", err)
		os.Exit(1)
	}
	defer reader.Close()

	decompressed, err := io.ReadAll(reader)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to read decompressed data: %v\n", err)
		os.Exit(1)
	}

	fmt.Printf("Decompressed %d bytes: %s\n", len(decompressed), string(decompressed))
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/klauspost/compress/zlib.ErrDictionary in pkg:golang/github.com/klauspost/compress@v1.19.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/klauspost/compress@v1.19.1"
  ],
  "symbols": [
    "github.com/klauspost/compress/zlib.ErrDictionary"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"errors"
	"fmt"
	"io"
	"os"

	"github.com/klauspost/compress/zlib"
)

func main() {
	if err := runContractTests(); err != nil {
		fmt.Fprintf(os.Stderr, "Contract test failed: %v\n", err)
		os.Exit(1)
	}
	fmt.Println("All contract tests passed successfully.")
}

func runContractTests() error {
	// 1. ErrDictionary is the sentinel error variable exported by zlib with message "zlib: invalid dictionary"
	{
		if zlib.ErrDictionary == nil {
			return fmt.Errorf("expected zlib.ErrDictionary to be non-nil")
		}
		if zlib.ErrDictionary.Error() != "zlib: invalid dictionary" {
			return fmt.Errorf("expected error string 'zlib: invalid dictionary', got %q", zlib.ErrDictionary.Error())
		}
	}

	// 2. NewReader returns ErrDictionary when decompressing a zlib stream that requires a preset dictionary
	{
		dict := []byte("contract-dictionary-alpha")
		payload := []byte("Data compressed with preset dictionary that requires a dict on read.")
		var buf bytes.Buffer
		zw, err := zlib.NewWriterLevelDict(&buf, zlib.DefaultCompression, dict)
		if err != nil {
			return fmt.Errorf("assertion 2: NewWriterLevelDict failed: %w", err)
		}
		if _, err := zw.Write(payload); err != nil {
			return fmt.Errorf("assertion 2: zw.Write failed: %w", err)
		}
		if err := zw.Close(); err != nil {
			return fmt.Errorf("assertion 2: zw.Close failed: %w", err)
		}

		_, err = zlib.NewReader(&buf)
		if !errors.Is(err, zlib.ErrDictionary) {
			return fmt.Errorf("assertion 2: expected ErrDictionary from NewReader, got: %v", err)
		}
	}

	// 3. NewReaderDict returns ErrDictionary when decompressing a stream with an incorrect preset dictionary
	{
		dictCorrect := []byte("correct-contract-dict-1")
		dictWrong := []byte("wrong-contract-dict-2")
		payload := []byte("Data compressed with dictCorrect to test dictionary mismatch detection.")
		var buf bytes.Buffer
		zw, err := zlib.NewWriterLevelDict(&buf, zlib.DefaultCompression, dictCorrect)
		if err != nil {
			return fmt.Errorf("assertion 3: NewWriterLevelDict failed: %w", err)
		}
		if _, err := zw.Write(payload); err != nil {
			return fmt.Errorf("assertion 3: zw.Write failed: %w", err)
		}
		if err := zw.Close(); err != nil {
			return fmt.Errorf("assertion 3: zw.Close failed: %w", err)
		}

		_, err = zlib.NewReaderDict(&buf, dictWrong)
		if !errors.Is(err, zlib.ErrDictionary) {
			return fmt.Errorf("assertion 3: expected ErrDictionary from NewReaderDict with wrong dict, got: %v", err)
		}
	}

	// 4. Resetter.Reset returns ErrDictionary when resetting an existing reader with an incorrect dictionary for dictionary-compressed data
	{
		dictCorrect := []byte("valid-reset-dictionary")
		dictWrong := []byte("invalid-reset-dictionary")
		payload := []byte("Payload for verifying Resetter.Reset dictionary validation.")

		var buf1 bytes.Buffer
		zw1, err := zlib.NewWriterLevelDict(&buf1, zlib.DefaultCompression, dictCorrect)
		if err != nil {
			return fmt.Errorf("assertion 4: NewWriterLevelDict 1 failed: %w", err)
		}
		if _, err := zw1.Write(payload); err != nil {
			return fmt.Errorf("assertion 4: zw1.Write failed: %w", err)
		}
		if err := zw1.Close(); err != nil {
			return fmt.Errorf("assertion 4: zw1.Close failed: %w", err)
		}

		var buf2 bytes.Buffer
		zw2, err := zlib.NewWriterLevelDict(&buf2, zlib.DefaultCompression, dictCorrect)
		if err != nil {
			return fmt.Errorf("assertion 4: NewWriterLevelDict 2 failed: %w", err)
		}
		if _, err := zw2.Write(payload); err != nil {
			return fmt.Errorf("assertion 4: zw2.Write failed: %w", err)
		}
		if err := zw2.Close(); err != nil {
			return fmt.Errorf("assertion 4: zw2.Close failed: %w", err)
		}

		zr, err := zlib.NewReaderDict(&buf1, dictCorrect)
		if err != nil {
			return fmt.Errorf("assertion 4: NewReaderDict initial failed: %w", err)
		}
		defer zr.Close()

		resetter, ok := zr.(zlib.Resetter)
		if !ok {
			return fmt.Errorf("assertion 4: reader does not implement zlib.Resetter")
		}

		err = resetter.Reset(&buf2, dictWrong)
		if !errors.Is(err, zlib.ErrDictionary) {
			return fmt.Errorf("assertion 4: expected ErrDictionary from resetter.Reset with wrong dict, got: %v", err)
		}
	}

	// 5. NewReaderDict succeeds and does not return ErrDictionary when the correct preset dictionary is provided
	{
		dict := []byte("correct-matching-dictionary-verification")
		payload := []byte("Payload to prove matching dictionary succeeds without error.")
		var buf bytes.Buffer
		zw, err := zlib.NewWriterLevelDict(&buf, zlib.DefaultCompression, dict)
		if err != nil {
			return fmt.Errorf("assertion 5: NewWriterLevelDict failed: %w", err)
		}
		if _, err := zw.Write(payload); err != nil {
			return fmt.Errorf("assertion 5: zw.Write failed: %w", err)
		}
		if err := zw.Close(); err != nil {
			return fmt.Errorf("assertion 5: zw.Close failed: %w", err)
		}

		zr, err := zlib.NewReaderDict(&buf, dict)
		if err != nil {
			return fmt.Errorf("assertion 5: expected nil error from NewReaderDict, got: %v", err)
		}
		defer zr.Close()

		decompressed, err := io.ReadAll(zr)
		if err != nil {
			return fmt.Errorf("assertion 5: io.ReadAll failed: %w", err)
		}
		if !bytes.Equal(decompressed, payload) {
			return fmt.Errorf("assertion 5: decompressed bytes mismatch")
		}
	}

	return nil
}

Seeder de origen

anónimo