scan

package
v0.0.0-...-3d40d98 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package scan refuses a source document before any of it is lowered.

The refusals share a phase and a subject. A reference cycle that never reaches a concrete schema recurses without bound inside the resolver. A reference whose pointer passes through a reference already being resolved deadlocks it, since the resolver holds that reference's own lock across the pointer walk. A YAML alias fan-out that expands to far more nodes than the document declares exhausts memory inside the parser. Each reads the raw text through nodeview, and each runs before the document is handed to either.

What the tree says about itself — its size, and whether an alias points back at one of its own ancestors — is not rederived here. The caller supplies a sourceindex.Index built over the same tree, so the questions that need only a walk are answered once for every refusal that asks them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cycles

func Cycles(srcIndex int, idx sourceindex.Index) []ir.Diagnostic

Cycles scans an indexed source tree for degenerate reference structures that would otherwise crash, hang or exhaust memory in the third-party parser and resolver (GitHub #12, GitHub #27, speakeasy-api/openapi#231), before soa.Unmarshal ever runs. It reports as error diagnostics: a recursive YAML anchor, a pure-$ref cycle (a chain of schema $refs that never reaches a node without one), a reference whose pointer resolves through a reference already being resolved, and alias amplification (a billion-laughs expansion). The scan runs under recoverCycleScan so a detector bug degrades to "no cycle found" rather than aborting.

The index is the caller's, built over the tree that will reach the parser: an overlay can graft a $ref cycle onto a document that had none, so a patched tree is re-indexed and re-scanned rather than trusted to the bytes that reached the overlay. The caller must not hand over a truncated index — every answer in one is partial, and the alias-expansion allowance derived from a partial node count would refuse documents on a bound they never crossed.

Only the decode that produced the tree bounds alias expansion inside the parser: the yaml.v3 alias budget is spent per Decode, so a tree that reached here without one has already escaped it and nothing here can re-run it.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL